Stack overflow.

Started by
32 comments, last by Calin 14 years, 8 months ago
Quote:The pointer is "consumed" when you use the index


I think I get it.

Quote:// 40 MB of fresh memory initialized to 0


how do you know thats 40 MByte of memory?

Is this how I create 65 thousand slots in the container

vector<color> LightMap;

for(int z =0; z < 65536; z++)
{
color C;
LightMap.push_back(C);
}

[Edited by - Calin on August 1, 2009 12:38:26 PM]

My project`s facebook page is “DreamLand Page”

Advertisement
Quote:Original post by Calin
Quote:// 40 MB of fresh memory initialized to 0

how do you know thats 40 MByte of memory?

Because on my system, sizeof(int) == 4, and 10000000 * 4 Byte = 40 MB.
Quote:Original post by Calin
Is this how I create 65 thousand slots in the container

There is no need to push them back, just create the vector with the correct size.
vector<color> LightMap(65536);
Quote:Original post by DevFred
Quote:Original post by Chadwell
Not quite. A multidimensional array on the heap is actually an array of arrays, and thus the array must contain pointers to point to those arrays.

You are confusing array of arrays with arrays of pointers. True multidimensional arrays on the heap are possible, it's just that the syntax looks a little funny.
int (*a)[4] = new int[4][4];delete[] a;

If the C declarator syntax gives you nightmares, use a typedef.
typedef int row[4];row *a = new row[4];delete[] a;


Hmm, I have never seen that syntax style before. Good to know, Thanks!
Quote:Original post by DevFred
vector<color> LightMap(65536);


will LightMap.resize(65536); achieve the same thing I can't call the constructor in the class declaration
Also can I have a vector of bools with the size 16 million (a 3 dimensional array with 256 resolution). I tried array but it didn't work.

/***********************/
int main()
{
bool Test[256][256][256];


for(int z = 0; z < 256; z++)
{
for(int y = 0; y < 256; y++)
{
for(int x = 0; x < 256; x++)
{
Test[z][y][x] = false;
}
}
}
return 0;
}


P.S I got to work with new()

[Edited by - Calin on August 7, 2009 3:33:58 AM]

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement