LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ListPreAllocate limitations?

I am using ListTypes in LabWindows/CVI 2015 15.0.0 (413).  Windows 7

 

When attempting to use the ListPreAllocate() function I am seeing what appears to be an undocumented limit to the pre cache memory that can be allocated.

 

I understand the requirements of contiguous available space for [m][c][re]alloc to succeed, and I suspect the same is true for initial allocation using ListPreAllocate.  So In the following code, I added a calloc statement to see if it would also fail.  It did not.  So, while I can allocate memory equivalent to 30 list items using malloc, the call to ListPreAllocate fails:

 

struct SCRIPT, has sizeof(SCRIPT) of approximately 8K. 

 

    char *buf = malloc(262080);//size equivalent to 30 * sizeof(SCRIPT)
    if(!buf) return -1;
    
    ListType list1;
    list1 = ListCreate(sizeof(SCRIPT));
    if(ListPreAllocate(list1, 30*sizeof(SCRIPT)) == 0) return -1;//fails here, whether or not the malloc call above is called.

I also observed that 25*sizeof(SCRIPT) was successful.

Is there a designed limit to the memory that can be allocated using this function?

Or some parameter that needs to be set?

 

 

0 Kudos
Message 1 of 2
(2,356 Views)

Hello ryk,

 

The 2nd parameter of ListPreAllocate is "Num Of Items To Preallocate". If you want to allocate memory for 30 structs you should pass 30 and not 30*sizeof(SCRIPT) because the list already knows that the size of an element is sizeof(SCRIPT) from ListCreate call. If you use 30*sizeof(SCRIPT) it actually allocates 30*8K*8K

 

Constantin

Message 2 of 2
(2,305 Views)