Xmem dynamic allocation

Hi:

I’m using Dynamic C 9.62 and RCM3229.

For my appliation I have to allocate certain fixed amount of data in xmem, and from that point I havo to allocate memory that later I have to reallocate. I hope that the next picture help me to explain better


| | Fixed portion of memory that do not have to reassign
|_________ |
| |
| | Portion of memory that I have to reasign continuously
| |
| |
|_________|

The amount of memory to be reasigned continuously is big and includes various blocks of extended memory.

I have developed two functions: the first in order to back up the point from that I can reasign memory, and the second in order to restores that point and when I use the next xalloc statement I can give the memory from the point that I have backed up.

The code for each one of this functions is like this:

1 st

void StoresStartXalloc()
{
auto _rk_xbreak_t xsbreak;
auto long next;

xsbreak.next = _rk_xubreak;
next = xsbreak.next;
// We mark the point from whe wanna being reusing the memory
xmem2root(&xsbreak, xsbreak.next, sizeof(_rk_xbreak_t));
memcpy(&InicioXalloc, &xsbreak, sizeof(_rk_xbreak_t));
root2xmem(next, &xsbreak, sizeof(_rk_xbreak_t));
}

2nd

void freexalloc()
{
root2xmem(_rk_xubreak, &InicioXalloc, sizeof(_rk_xbreak_t));
}

The above functions seems to work fine while I don’t use allocations to NVRAM between the call to the first function and the call to the second function, but when I use NVRAM it doesn’t work

Some idea?

Thank you in advance!!