C++ 查看new空间大小

来自泡泡学习笔记
跳到导航 跳到搜索
#include<iostream>

typedef struct _RTL_HEAP_ENTRY {
      unsigned int Size;
      short Flags;
      short AllocatorBackTraceIndex;
      union {
              struct {
                      unsigned int Settable;
                      long Tag;
              } s1;
      } u;
} RTL_HEAP_ENTRY, *PRTL_HEAP_ENTRY;

int main() 
{
    int a;

    int *p = new int[10];
    PRTL_HEAP_ENTRY pHeapEntry=(PRTL_HEAP_ENTRY)p-1;
    std::cout << "size: " << pHeapEntry->Size << std::endl;
    std::cout << *(p - 4) << std::endl;

    delete[] p;
}