看板Programming
标 题Re: [问题] 存取实体记忆体的方法?
发信站椰林风情 (Sat Jun 23 20:18:10 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!Palmarama
==> [email protected] (打字男) 提到:
> 请问一下 如何用 c或asm 去存取到实体记忆体呢?
> 我有这个需求,但对这方面观念还不是很了解
> 希望能够获得一些指点
> 若有人可以写几行给小的参考 也会对我很有帮助
> 感谢
请参考 Borland C++ Builder 的 new 指令,可以取代以前的 malloc(),
The new operators offer dynamic storage allocation,
similar but superior to the standard library function malloc.
These allocation functions attempt to allocate size bytes
of storage. If successful, new returns a pointer to the
allocated memory.
If the allocation fails, the new operator will call the
new_handler function. The default behavior of new_handler is
to throw an exception of type bad_alloc. If you do not want
an exception to be thrown, use the nothrow version of operator
new. The nothrow versions return a null pointer result on
failure, instead of throwing an exception.
The default placement forms of operator new are reserved and
cannot be redefined. You can, however, overload the placement
form with a different signature (i.e. one having a different
number, or different type of arguments). The default placement
forms accept a pointer of type void, and perform no action
other than to return that pointer, unchanged. This can be
useful when you want to allocate an object at a known address.
Using the placement form of new can be tricky, as you must remember
to explicitly call the destructor for your object, and then free
the pre-allocated memory buffer. Do not call the delete operator
on an object allocated with the placement new operator.
A request for non-array allocation uses the appropriate operator
new() function. Any request for array allocation will call the
appropriate operator new[]() function. Remember to use the array
form of operator delete[](), when deallocating an array created
with operator new[]().
Note: Arrays of classes require that a default constructor be
defined in the class.
A request for allocation of 0 bytes returns a non-null pointer.
Repeated requests for zero-size allocations return distinct,
non-null pointers.
--
在每个人刚出生的时候 , 神早已为人类世界留下了伏笔 .
个人网页
http://myweb.hinet.net/home4/l1032265/index.htm
--
☆ [Origin:椰林风情] [From: 122-124-13-219.dynamic.hine] [Login: **] [Post: **]