Is there a memory limit for the "new" operator?
-
I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint
-
I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint
-
I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint
I'm not sure if this coincide with what you need... I needed a buffer for file manipulation. The "new" seemed to be limited to 64k of memory. A work around this uses structures. Declare a structure with elements (in my case, BYTE) as array of size 0xff (65,535). If you need more than 64k of memory, declare more array of BYTE's. In order to use it, declare a variable of the structure and a pointer to BYTE. Then point the pointer to the first element of the structure, and voila!, you have a buffer array of more than 64k! Just use the pointer to access the buffer. (elements declared in a structure are allocated continously). Note: if elements are of size 0xff each, I noticed that one can not have more than 16 elements. Ofcourse, I might be wrong. typedef struct BUFFER { BYTE Buffer0 [0xff]; BYTE Buffer1 [0xff]; ... BYTE BufferN [0xff]; } BUFFER; void Some_Function () { BUFFER Buffer; BYTE *pBuffer; pBuffer = Buffer.Buffer0; memset (pBuffer, 0, ); ... } :)
-
I'm not sure if this coincide with what you need... I needed a buffer for file manipulation. The "new" seemed to be limited to 64k of memory. A work around this uses structures. Declare a structure with elements (in my case, BYTE) as array of size 0xff (65,535). If you need more than 64k of memory, declare more array of BYTE's. In order to use it, declare a variable of the structure and a pointer to BYTE. Then point the pointer to the first element of the structure, and voila!, you have a buffer array of more than 64k! Just use the pointer to access the buffer. (elements declared in a structure are allocated continously). Note: if elements are of size 0xff each, I noticed that one can not have more than 16 elements. Ofcourse, I might be wrong. typedef struct BUFFER { BYTE Buffer0 [0xff]; BYTE Buffer1 [0xff]; ... BYTE BufferN [0xff]; } BUFFER; void Some_Function () { BUFFER Buffer; BYTE *pBuffer; pBuffer = Buffer.Buffer0; memset (pBuffer, 0, ); ... } :)
Just vondering why you don't use malloc() instead. :confused: - Anders Money talks, but all mine ever says is "Goodbye!"
-
Just vondering why you don't use malloc() instead. :confused: - Anders Money talks, but all mine ever says is "Goodbye!"
Well from the CRT source code it looks like malloc was using from the dynamic heap. I looked into the heap size and it can't be bigger than about 500k. I ended up just saving that precious heap and used GlobalAlloc instead.
-
Well from the CRT source code it looks like malloc was using from the dynamic heap. I looked into the heap size and it can't be bigger than about 500k. I ended up just saving that precious heap and used GlobalAlloc instead.
It uses memory from the global heap. It's no problem to alloc 50MB with malloc() - Anders Money talks, but all mine ever says is "Goodbye!"