LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How increase the dinamic memory allocation using malloc?

Hello,

 

I am trying to allocate dinamically 3 pointers in memory. First one will storage a binary file, bigger than 1GB, as char, second one would be a copy from first, but as Uint16 (unsigned short). Third one would be a 3x3 matrix double type. I am using malloc to allocate those pointers.

 

cBuffer = (char*) malloc(size*sizeof(char))

iBuffer = (unsigned short*) malloc(size*sizeof(unsigned short))

dMatrix = (double***)malloc(size*sizeof(int))

for(i=0; i<size; i++)

    dMatrix[i]=(double**)malloc(size*sizeof(unsigend short))

    for(j=0; i<size;i++)

       dMatrix[j]=(double*)malloc(size2*sizeof(double))

 

where "size" always would be bigger than 1GB and size2 is a little bit bigger than size, cBuffer is a pointer to char, iBuffer is a pointer to unsigned int and dMatrix is a pointer 3*3 to a double.


The problem is when I try to allocate memory for iBuffer, CVI can not allocate it, malloc function returns me a NULL pointer.

 

Someone knows how can I allocate huge buffers in memory using malloc?

 

I am working in a PC with Windows XP SO and 4 GB  in RAM, so I have enough memory to do it. 500GB in HDD

 

Thanks in advance!

Hiram Hernandez

0 Kudos
Message 1 of 5
(4,781 Views)
On a 32 bit system, size*sizeof() cannot be larger than 2 GB. Because sizeof () will return something like 4 or 8 bytes, size itself has to be correspondingly smaller.
0 Kudos
Message 2 of 5
(4,770 Views)
This is an interesting discussion that spans over huge memory allocation, also covering some topics on using compilers different than CVI native one to obtain better behaviour in this matter.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 5
(4,766 Views)
Because your system has 4GB, doesn't mean that it is all available to you.  I think that you can access somewhat less that 2 GB because the OS takes the rest.  I have a very similar hardware setup to you with WinXP and usually the most I can allocate in no more that 1.5 GB.
0 Kudos
Message 4 of 5
(4,755 Views)

Thanks to all,

So I need change to a 64 bits system in order to process more than 1.5GB in memory.

0 Kudos
Message 5 of 5
(4,712 Views)