QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
Allocating large amounts of memory |
Ref. No. |
QNX.000009491 |
Category(ies) |
Development |
Issue |
During QNX4 development in C using Watcom 10.6, a large amount of memory needs to be allocated. calloc() does not appear to work. Neither does _fcalloc() or halloc(). These last two functions produce linker errors when compiled that sound like it can't find the functions.
|
Solution |
Do not use halloc() for this as it has a limit on the array size of 64k. The behaviour of calloc(), _fcalloc() and related functions depend on which memory model being used. If this changes, a different function will have to be used.
malloc() should be used whenever possible because it is the same for any memory model. Large amounts of memory are the same as small ones. When allocating large amounts of memory, the flat memory model (cc -mf) should be used as it allows for up to 4G of data and 4G of code, which should be more than enough for any program.
Always remember to free any memory that is malloc'd. While cleanup may be done automatically in some cases, this is not always the case and will cause problems. A small example is:
--- #include <stdio.h> void main() { x09char * bigMemory; x09unsigned int available = 10000000; /* NOTE: this assumes you have 10 Megs of free RAM. if you don't well you'll see... */ x09bigMemory = (char *) malloc ( available) ;
if ( bigMemory != NULL ) printf (" it worked. YAY! n");
free ( bigMemory ); return ; } ---
The memory indicated in the program is more than is available on your system, do a "sin in" to find the free memory. Then change the available variable to slightly under that amount.
See Also: calloc in Watcom C Library - A to M See Also: halloc in Watcom C Library - A to M See Also: malloc in Watcom C Library - A to M |
|