操作员新功能在哪里存储大小? [英] Where does the operator new function store the size?

查看:117
本文介绍了操作员新功能在哪里存储大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我很想知道标准/普通的新操作符"功能实现在哪里存储变量的大小.从C ++规范中知道,运算符新表达式扩展为适当类的运算符新函数的调用.该调用传递要分配的内存的size_t.

但是函数在哪里存储大小?我的意思是,delete和sizeof运算符必须从某处获得此大小吗?!
我的第一个想法是,它将被存储在数据的前面(类似BSTR),但是除了在内存视图窗口中的数据本身之外,我再也没有看到过.
例如,如果我创建一个值为3的int,则内存本身只有"0x03",之前或之后没有大小...


问候,

Allgaeuer

解决方案

请参阅类似的讨论:
标准新操作员如何工作 [ ^ ]
如何"malloc"和新"作品 [ GDT [ LDT [ ^ ],具体取决于其第2位状态.然后,地址寄存器在平面内存模型的情况下指向内存本身,或者在虚拟模式的情况下指向页索引+偏移量.最重要的是,这几天内存实际上是在页面中分配的,并且x86处理器支持swap标志,因此,只要任务试图访问标记为已交换的页面,并且处理程序将其加载,它就可以触发中断.是的,那个老栗子.这也是它在Windows中的工作方式;)

您是否还想知道您的内存大小存储在哪里? :) :) :)进程内的内存大小始终是虚拟的,而不是真实的,并且可以存储在任何地方,只要支持的API知道如何处理它即可.欢迎来到虚拟时代,我的朋友;)

P.S.这不是大小,伴侣,而是您的使用方式:) :):)


Hello folks,

i would be heavily interested, to know where a standard/normal "operator new"-function implementation does store the size of the variable. I know from the C++ specification, that the operator new expression expands to a call of the operator new function, of the appropriate class. This call passes the size_t of the memory to allocate.

But where does the function store the size? I mean, the delete and the sizeof operator must get this size from somewhere?!
My first idea was, it would be stored in-front of the data (BSTR like), but i have never seen anything else than the data itself in the memory view window.
For example, if i create an int with value 3, there is only the "0x03" itself at the memory, no size before or behind...


greetings,

Allgaeuer

解决方案

Refer similar discussion:
How does the standard new operator work[^]
How do ''malloc'' and ''new'' work[^]


Operator new inside usually calls the API function HeapAlloc. Operator delete calls HeapFree. As you can see, this is all WinAPI inside. Now all you need is to use heap api.
Memory is allocated by blocks, much like a linked list. All you need is to walk these blocks. Try using HeapWalk.


There are numerous implementations of the new operator from one compiler to the next, plus there are many ways to allocate different types of memory, such as local or global, or in stack or in the heap.

Read about memory management on the platform where your question applies, and about the exact methods of memory allocation that you use.

Beside that, I can only tell you where memory pointer is allocated physically on the x86 platform, regardless of some high-level operators, if you are curious ;) And it goes like this...(no, u think u''re ready?) :)

First of all, selector register points at either GDT[^] or LDT[^], depending on its bit 2 status. Then the address register points at either memory itself, in case of flat memory model, or page index + offset, in case of the virtual mode. The bottom line, memory is physically allocated in pages these days, and the swap flag is supported by the x86 processors, so it can trigger an interrupt wherever a task is trying to access a page marked as swapped and the handler loads it up. Yep, that old chestnut. And this is how it works in Windows too ;)

Do you still want to know where your memory size is stored? :) :) :) Memory size within a process is always virtual, not real, and it can be stored anywhere, as long as the supporting API knows how to deal with it. Welcome to the virtual age, my friend ;)

P.S. It''s not the size, mate, it''s how you use it :) :) :)


这篇关于操作员新功能在哪里存储大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆