1

Came across a code which allocate memory like this:

int iPage_size = getpagesize ();
int iNeedSize = (iNeedSize + iPage_size - 1) & ~(iPage_size - 1);
void* iBuffer = memalign (iPage_size, iNeedSize);

1. So why is that different from this:

void* iBuffer = malloc(iNeedSize);

2. And can I re-allocate that buffer which is allocated by memalign using realloc? or do I need to free it first and do memalign again?

Thanks.

P/s: above snippets of code is taken from a code working on V4L2-driver device.

Trung Nguyen
  • 177
  • 1
  • 12

0 Answers0