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.

Using calloc (or malloc) for a Circular Buffer

I've already posted a similar post on a different thread in the TI C/C++ Compiler Forum, but I'm having issue in regards to using the calloc function when developing a circular buffer. The code for initializing the circular buffer is shown below, (as well as in the link provided).

/*************CIRCULAR BUFFER*************/
typedef struct { unsigned char value; } ElemType;

// Circular buffer object //
typedef struct
{
    int         size;   // maximum number of elements
    int         start;  // index of oldest element
    int         end;    // index at which to write new element
    ElemType   *elems;  // vector of elements
} CircularBuffer;

CircularBuffer cb;
ElemType elem = {0};
int testBufferSize = 0x100; // arbitrary size //

void cbInit(CircularBuffer *cb, int size)
{
    cb->size  = size + 1; // include empty elem //
    cb->start = 0;
    cb->end   = 0;
    cb->elems = (ElemType *)calloc(cb->size, sizeof(ElemType));
}

I've reviewed the linker file and the project properties in CCS version 5.5.  I've also increased the heap size to make it larger than the test buffer size I set in my code.  However, this has not removed the Warning I am getting:


#10229-D output section ".data" refers to load symbol "_nop" and hence cannot be compressed; compression "rle" is ignored SPI Sniffer FR5739 C/C++ Problem

I'm still combing through the manual and the forums to find a solution, but I would like to get this fixed so that my MSP430 FR5739 will function correctly.  Are there any suggestions 

  • Why do you want to use calloc? If you need th ebuffer, you can declare it as a global or static array. THis way it will be initialized at startup, the linker knows that this space is requied and can throw an error if oyu overuse your ram, and you don't need to mess with the dynamic memory allocation stuff.

    I don't know why you get this warning, but the linker tries to store the init values for global variables in compressed format to save storage space, and expands it into ram at program start. It apparently cannot do this 'Run Length Encoding' under some circumstances.
    A possible reason is that this compression is done 'on-the-fly' as code is linked, and if your global or static variables contain any circular references, this can't be done and the init data has to be stored uncompressed.

    Chances are that the warning has nothing to do with your usage of calloc. Maybe it is a problem with the calloc library code in general. However, the only effect is that the init data requires more space (but then, the init process is done quicker).

**Attention** This is a public forum