作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在自己的虚拟内存页面上分配一个NSObject
。这可能吗?如果我们仍然可以使用NSZone
,这似乎很琐碎,但已弃用了它们。我尝试使用NSZoneFromPointer
,但始终返回nil
。根据Tips for Allocating Memory:
对于较大的内存分配,其中的大小不止几个
虚拟内存页面,malloc自动使用vm_allocate
例程获取请求的内存。
因此,看来我应该能够使我的对象像这样大到几页:
@interface MyObject : NSObject {
int[40960]; // 4096 is the default page size, so this is 10 pages.
}
@implementation MyObject
@end
最佳答案
从twitter:
objc_constructInstance(…)可以让您做您想做的...
从<objc/runtime.h>
:
/**
* Creates an instance of a class at the specific location provided.
*
* @param cls The class that you wish to allocate an instance of.
* @param bytes The location at which to allocate an instance of \e cls.
* Must point to at least \c class_getInstanceSize(cls) bytes of well-aligned,
* zero-filled memory.
*
* @return \e bytes on success, \c nil otherwise. (For example, \e cls or \e bytes
* might be \c nil)
*
* @see class_createInstance
*/
OBJC_EXPORT id objc_constructInstance(Class cls, void *bytes)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0)
OBJC_ARC_UNAVAILABLE;
objc_constructInstance
是答案。
关于ios - 如何在iOS中将NSObject分配到其自己的虚拟内存页面上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19362430/
我是一名优秀的程序员,十分优秀!