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 memory pragma for dynamic memory allocation

hi all,

can i use the memory pragma for dynamic memory allocation?

example:


#pragma DATA_ALIGN(x,16)

int *x;

x=(int*)malloc(variable_size*sizeof(int));

regards

phani tej

  • If you want to align the address of the dynamically allocated memory, then call memalign() instead of malloc().

    [In your example code the DATA_ALIGN will apply to the address of the pointer variable x, rather than the address of dynamically allocated memory]

  • satya phani tej nittala said:
    can i use the memory pragma for dynamic memory allocation?

    No.

    If you build for ARM or C6000, then you call the RTS function memalign.  The prototype is ...

    void  *memalign(size_t _aln, size_t _size);

    The first argument is the alignment required, e.g. 16 for 16-byte alignment.  The second argument is the number of bytes requested, just like malloc.

    Thanks and regards,

    -George