79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
- (instancetype)initWithItemSize: (size_t)itemSize
count: (size_t)count
{
self = [super init];
@try {
size_t size, pageSize;
if OF_UNLIKELY (itemSize == 0)
@throw [OFInvalidArgumentException exception];
if OF_UNLIKELY (count > SIZE_MAX / itemSize)
@throw [OFOutOfRangeException exception];
size = itemSize * count;
pageSize = [OFSystemInfo pageSize];
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
_mappingSize = OF_ROUND_UP_POW2(pageSize, size);
if OF_UNLIKELY (_mappingSize < size)
@throw [OFOutOfRangeException exception];
if OF_UNLIKELY ((_items = mmap(NULL, _mappingSize,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) ==
MAP_FAILED)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: _mappingSize];
if OF_UNLIKELY (mlock(_items, _mappingSize) != 0)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: _mappingSize];
of_explicit_memset(_items, 0, _mappingSize);
#else
if OF_UNLIKELY ((_items = malloc(size)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: size];
of_explicit_memset(_items, 0, size);
#endif
_itemSize = itemSize;
_count = count;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
|
>
>
>
<
<
>
<
<
<
<
>
>
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
- (instancetype)initWithItemSize: (size_t)itemSize
count: (size_t)count
{
self = [super init];
@try {
size_t size;
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
size_t pageSize;
#endif
if OF_UNLIKELY (itemSize == 0)
@throw [OFInvalidArgumentException exception];
if OF_UNLIKELY (count > SIZE_MAX / itemSize)
@throw [OFOutOfRangeException exception];
size = itemSize * count;
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
pageSize = [OFSystemInfo pageSize];
_mappingSize = OF_ROUND_UP_POW2(pageSize, size);
if OF_UNLIKELY (_mappingSize < size)
@throw [OFOutOfRangeException exception];
if OF_UNLIKELY ((_items = mmap(NULL, _mappingSize,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) ==
MAP_FAILED)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: _mappingSize];
if OF_UNLIKELY (mlock(_items, _mappingSize) != 0)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: _mappingSize];
#else
if OF_UNLIKELY ((_items = malloc(size)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: size];
#endif
_itemSize = itemSize;
_count = count;
[self zero];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|