Showing posts with label Linux function. Show all posts
Showing posts with label Linux function. Show all posts

[Linux]malloc_usable_size使用注意事項

在windows下有個可以取得malloc的buffer size的函式-_msize()。

然而在linux底下是沒有相同的函式,所以後來又去網路上找到malloc_usable_size()這個函式。

雖然malloc_usable_size()可以取得到buffer size,不過呢,因為他是dependence on aligment。

所以取得的大小會等於或大於原本buffer size,如果要用來作比對或者是buffer大小計算的話,這邊就很容易出錯了。

至於替代方案目前還沒找到,所以有找到後再補上吧。

以下是參考連結:
http://www.slac.stanford.edu/comp/unix/package/rtems/doc/html/libc/libc.info.malloc.html


以下是部分文字節錄:
   The `malloc_usable_size' function takes a pointer to a block
allocated by `malloc'. It returns the amount of space that is
available in the block. This may or may not be more than the size
requested from `malloc', due to alignment or minimum size constraints.

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...