C++ 查看new空间大小

来自泡泡学习笔记
BrainBs讨论 | 贡献2024年12月4日 (三) 12:43的版本 (创建页面,内容为“ #include<iostream> <pre> 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: " << pHeapEntr…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索
  1. 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;
}