malloc.h文件找不到malloc_usable_size

我要获取我分配的动态内存大小,我开始用的sizeof(p)无论分配多大,获取的值一直是4,我想可能不对。
查看网上很多回答说可以用malloc_usable_size(p)获取
但我引入头文件#include ,运行代码提示找不到malloc_usable_size() , C/c++都尝试了,一样的错误



#include ;
#include 

int main()
{
    char *p = malloc(100);
    char *h = p - 8;
    printf("%d\n", malloc_usable_size(p));

    return 0;
}

img


截图是我手动去查看malloc.h 文件确实没有找到 malloc_usable_size方法
错误 LNK2019 无法解析的外部符号 _malloc_usable_size,该符号在函数 _main 中被引用 CLearn E:\code_data\vs\c_learn\CLearn\CLearn\main.obj

_msize
Returns the size of a memory block allocated in the heap.

size_t _msize( void *memblock );

Routine Required Header Compatibility
_msize <malloc.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_msize returns the size (in bytes) as an unsigned integer.

Parameter

memblock

Pointer to memory block

Remarks

The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc.

When the application is linked with a debug version of the C run-time libraries, _msize resolves to _msize_dbg. For more information about how the heap is managed during the debugging process, see Using C Run-Time Library Debugging Support.

Example

/* REALLOC.C: This program allocates a block of memory for
 * buffer and then uses _msize to display the size of that
 * block. Next, it uses realloc to expand the amount of
 * memory used by buffer and then calls _msize again to
 * display the new amount of memory allocated to buffer.
 */

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

void main( void )
{
   long *buffer;
   size_t size;

   if( (buffer = (long *)malloc( 1000 * sizeof( long ) )) == NULL )
      exit( 1 );

   size = _msize( buffer );
   printf( "Size of block after malloc of 1000 longs: %u\n", size );

   /* Reallocate and show new size: */
   if( (buffer = realloc( buffer, size + (1000 * sizeof( long )) )) 
        ==  NULL )
      exit( 1 );
   size = _msize( buffer );
   printf( "Size of block after realloc of 1000 more longs: %u\n", 
            size );

   free( buffer );
   exit( 0 );
}



Output

Size of block after malloc of 1000 longs: 4000
Size of block after realloc of 1000 more longs: 8000

Memory Allocation Routines

See Also calloc, _expand, malloc, realloc

sizeof(p)计算的是 p 指针占用的内存,32位系统就是4字节,不能计算指针指向的内存大小。
malloc_usable_size 这个函数应该是只在 linux 下才能使用吧。