472,969 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

Memory access error with STL composed types

Hi all.
First of all let me apologize by my english.
I've googled a lot about my problem, but I had not find anything conclusive.
I have the following piece of code:

Expand|Select|Wrap|Line Numbers
  1. vector < map < int , char * > > bank;
  2. bank . reserve ( 10 );
  3. if ( bank [ 0 ] [ 0 ] == "a" ) //Memory access error (Access violation at address #blabla)
which give me the error indicated in comment.
So, to test, I included the following line before "if", and the error changes to that line

Expand|Select|Wrap|Line Numbers
  1. bank [ 0 ] [ 0 ] = "b"; //Same error
Finally, the following inserted in place of the line above, works.
Expand|Select|Wrap|Line Numbers
  1. map < int , char * > data;
  2. data [ 0 ] = "a";
  3. bank . push_back ( data );
But this is hardly an option to me. Mainly because I need, most of times, to test the variable "bank" (even the NULL address existence, which tells me that new item insertion is ok) before I can decide what to do. Beside that, that association grows interactively.
As I can see, it seems a problem with map allocation.
So, my exactly question is how can I use this type of association ( vector < map < type1 , type2 > > ) without get into Mermory access violation errors? Is there a way to previously initialize that association in a manner that allow me to insert new element just doing
Expand|Select|Wrap|Line Numbers
  1. bank [ i ] [ j ] = "some"
even after the limits previously defined (growing the association)?
Please excuse me if this is trivial, but I'm new to STL.
I appreciate any helps.
Thanx in advance.
Nov 15 '07 #1
4 2227
9,208 Expert Mod 8TB
I see the vector named bank.

I do not see that this is a two-dimensional array so your bank[x][y] syntx just will not work.

If you are new to STL, then this vector is a very advanced one indeed for you to be using. Maybe you could tell me what youare trying to do. It may be you are doing things the hard way.
Nov 15 '07 #2
In fact, I've change it a bit. What I have is vector < map < int , Object * > >, but I think it does'nt matter. What I need is exaclty what I try to represent.An array with each element having an associative array. To clarify: each position of the array represent a level. In each level I've a group of cells (of a grid) that I must inspect and I use their index as a key in associative array.
You say that bank [ i ] [ j ] does'nt look like a bidimensional array for you. But, in fact, I can get the array element value when I do var = bank [ i ] [ j ] (of course, when I use push_back first). So, it is a lot confusing to me. Any ideas?
Nov 16 '07 #3
I forgot to say something very important. I do not know previously, the size of array (vector) or associative array (map). They grow interactively in execution time and their size may vary in a wide range ( to few hundreeds from hundreeds of thousands and even million).
Nov 16 '07 #4
9,208 Expert Mod 8TB
What I need is exaclty what I try to represent.An array with each element having an associative array.
This would be a vector where each element is itself a vector.
Expand|Select|Wrap|Line Numbers
  1. vector< vector<Object*> > bank;
Now the bank[i][j]syntax will work.

If you are accessing by a key then you may want a map where each element is itself another map.
Expand|Select|Wrap|Line Numbers
  1. map< int, map<int, Object*> > bank;
Here you would specify a key to get a map and then specify another key to get an Object* from that second map.

Here you could use bank[i][j] to get on Object*.
Nov 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Benjamin Scott | last post by:
Hello. I attempted to build a compound dictionary: len(Lst)=1000 len(nuerLst)=250 len(nuestLst)=500 Dict={}
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
by: Ian | last post by:
I have and Access 97 DB that prints a report that has many pages, sometime about 800-1000 page, each page contains a colour picture along with text boxes. The pictures are displayed on the...
by: aling | last post by:
Have following code snip: struct struc { int member1; int member2; } ; printf("&((struc*)0)->member2=%p\n", &((struc*)0)->member2); In VC7.1, the output is 4, the offset of member2 in struc.
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
by: K. Jennings | last post by:
I would like to get the result of malloc() such that it is aligned on a given boundary - 8, in this case. Assuming that sizeof(u64) is 8, will u64 *p = malloc(N) ; do the trick in general? ...
by: jlm699 | last post by:
Greetings all, I'm using a PHP-based web page to access an SQL database containing logs which has grown quite large over time. A few weeks ago I recieved the following error: "Fatal error: Allowed...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.