Sample Header Ad - 728x90

On some UNIX implementations, it is not possible to call free() on a block of memory allocated via memalign()

1 vote
1 answer
368 views
I use Linux only but I want to understand what this means: From *the Linux Programming Interface*: > Blocks of memory allocated using memalign() or posix_memalign() > should be deallocated with free(). > > On some UNIX implementations, it is not possible to call free() on a > block of memory allocated via memalign(), because the memalign() > implementation uses malloc() to allocate a block of memory, and then > returns a pointer to an address with a suitable alignment in that > block. The glibc implementation of memalign() doesn’t suffer this > limitation. From man memalign: > POSIX requires that memory obtained from posix_memalign() can be > freed using free(3). Some systems provide no way to reclaim memory > allocated with > memalign() or valloc() (because one can pass to free(3) only a pointer obtained from malloc(3), while, for example, > memalign() would call malloc(3) and > then align the obtained value). The glibc implementation allows memory obtained from any of these functions to be reclaimed > with free(3). I don't know much about memory alignment and don't understand on "*for example, memalign() would call malloc(3) and then align the obtained value*". Could someone tell me what's going on here and what could be wrong with free()?
Asked by Rick (1247 rep)
Aug 27, 2022, 03:18 AM
Last activity: Aug 27, 2022, 05:33 AM