This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

calloc() will not exceed 0xFFFF?

Guru 15580 points

I am trying to create a large buffer in my heap by using calloc. However, if the size of the calloc size parameter exceeds 0xFFFF the function returns a null pointer. I have set the heap to 0x12000 words (0x24000 bytes) in my linker file. I can verify that the heap is properly allocated by looking at the map file. But calloc refuses to allocate more than 0xFFFF words of memory. I am using a large memory model.

Below is my code. Can anyone offer a suggestion?

void mem_test()
{
size = 0x10000; //this size returns a null pointer....
minit();
char_size = sizeof(unsigned char);
buffer = (unsigned char*) calloc (size, char_size );
memset(buffer, 0x55, size);
}

  • For which ISA? If that ISA has memory models, which memory model?  What are your exact command-line options?

  • I gather from your posting history that you are using C55x, and you said you are using large model.  Even in marge model, objects may not be larger than a single page.  Furthermore, the functional size of the heap (.sysmem, which is the dynamic memory pool) is limited to one page, as well.  A request for 0xffff bytes cannot be satisfied, because the allocator always allocates slightly more than requested so that it can add bookkeeping information.  Even if you make .sysmem much larger, malloc will only be able to take advantage of the first page; the rest will be wasted.  In order to allocate objects that large, you will need to use huge model (--memory_model=huge)

  • Arch,

    Sorry, forgot to mention C55xx using large memory model. Using CCSv5.3 (not sure what an ISA is....)

    Compiler

    -v5515 --memory_model=large -g  --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/ARL_5515/fonts" --include_path="C:/Users/Mike/TI Workspaces/Fonts" --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/dsplib_c55xx/include" --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/usbstk5515bsl/include" --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/ARL_5515/inc" --include_path="C:/ti/c55xx_csl/inc" --include_path="C:/ti/ccsv5/tools/compiler/c5500_4.4.1/include" --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/ARL_5515/Debug" --include_path="C:/ti/bios_5_41_11_38/packages/ti/bios/include" --include_path="C:/ti/bios_5_41_11_38/packages/ti/rtdx/include/c5500" --include_path="C:/Users/Mike/TI Workspaces/ARL5515_FF1/ARL_5515/Debug" --define="_DEBUG" --define=HAVE_STDINT_H --define=HAVE_CONFIG_H --define=C55X --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --algebraic

    Linker

    -v5515 --memory_model=large -g --define="_DEBUG" --define=HAVE_STDINT_H --define=HAVE_CONFIG_H --define=C55X --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --algebraic -z -m"ARL100_DSPFW_v1.0.map" --stack_size=0x200 --heap_size=0x400 -ii"C:/ti/ccsv5/tools/compiler/c5500_4.4.1/lib" -i"C:/ti/ccsv5/tools/compiler/c5500_4.4.1/include" -i"C:/Users/Mike/lib" -i"C:/ti/bios_5_41_11_38/packages/ti/rtdx/lib/c5500" -i"C:/ti/bios_5_41_11_38/packages/ti/bios/lib" -i"C:/Users/Mike/TI Workspaces/ARL5515_FF1/ARL_5515" --reread_libs --warn_sections --rom_model --sys_stacksize=0x200

    CMD file

    -stack 0x2000
    -sysstack 0x2000
    -heap 0x24000 

    Map File

    .sysmem 0 [ 00010000 ] 00008000 * 00012000 UNINITIALIZED
    [ 00010000 ] 00008000 * 00012000 --HOLE--

    Thanks for taking a look.

  • Arch,

    Ok thanks. I'll try migrating to Huge.

  • MikeH said:
    (not sure what an ISA is....)

    Instruction Set Architecture http://en.wikipedia.org/wiki/Instruction_set_architecture

  • Recompiled the project code and all libraries to huge model and the calloc now works as expected. Thanks!