Page 1 of 1

PostPosted: Mon Oct 28, 2002 6:05 am
by joh.becker

Is there a size limitation for objects created with malloc()? I had a problem and found that malloc(62000) works but malloc(63000) or bigger failes by not returning from malloc.

Any experience or workarounds?


PostPosted: Mon Oct 28, 2002 8:10 am
by Nik
> Is there a size limitation for objects created with malloc()?

Yes, max. number of all vars = 64k
Try to use, Guys library instead. There`s no such limitation.


PostPosted: Mon Oct 28, 2002 10:06 am
by guy
The only thing that you have to worry about when using LocalAlloc() or HeapAlloc() is running out of virtual memory. Early versions of CE had a limit on the size of heaps, but the later ones don't.

You also have to use the memory access functions instead of PocketC pointers to get at the memory. There is a speed implication in calling a function for every memory access (even though the function itself is written in evc).


#include "/pocketc/winbase.h"

#define NUM_INTS 64000 // Go on, up that to a megabyte and see what happens
#define INDEX 12345

LPVOID lpMemory ;
int iSize ;
int iValue ;

iSize = sizeofx("i") ; // get size of an integer (=4)

lpMemory = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, NUM_INTS * iSize) ;

// Following can be optimised to remove multiplication

memwrite32(lpMemory + (INDEX * iSize), 42) ;

iValue = memread32(lpMemory + (INDEX * iSize)) ;


LocalFree(lpMemory) ; // Don't forget this

If you are manipulating groups of entries, it is faster to use the memreadArray/memwriteArray functions to transfer blocks of variables from a small PocketC array into the real array. Or use the memreadStruct/memwriteStruct functions.

PocketC CE API interface:
PCForm and CE API forum: