parsav  Diff

Differences From Artifact [7e2b478eaf]:

To Artifact [05a21ff4d9]:


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
	self.sz = sz
	self.debris = [&m.pool](b)
	self.debris.storage = nil
	return self
end

terra m.pool:free(): {}
lib.io.fmt('DRAINING POOL %p\n',self.storage)
	if self.storage == nil then return end
	if self.debris.storage ~= nil then self.debris:free() end
	m.heapf(self.debris) -- storage + debris field allocated in one block
	self.storage = nil
	self.cursor = nil
	self.sz = 0
	self.debris = nil
................................................................................
terra m.pool:clear()
	if self.debris.storage ~= nil then self.debris:free() end
	self.cursor = self.storage
	return self
end

terra m.pool:alloc_bytes(sz: intptr): &opaque
	var space = self.sz - ([&uint8](self.cursor) - [&uint8](self.storage))
lib.io.fmt('%p / %p @ allocating %llu bytes in %llu of space\n',self.storage,self.cursor,sz,space)
	if space < sz then
lib.dbg('reserving more space')
		self:cue(space + sz + 256) end
	var ptr = self.cursor
	self.cursor = [&opaque]([&uint8](self.cursor) + sz)
	return ptr
end

terra m.pool:realloc_bytes(oldptr: &opaque, oldsz: intptr, newsz: intptr): &opaque
	var space = self.sz - ([&uint8](self.cursor) - [&uint8](self.storage))
	var cur = [&uint8](self.cursor)
	if cur - [&uint8](oldptr) == oldsz and newsz - oldsz < space then
		lib.dbg('moving pool cursor')
		cur = cur + (newsz - oldsz)
		self.cursor = [&opaque](cur)
		return oldptr
	else







<







 







|
<

<
|






|







207
208
209
210
211
212
213

214
215
216
217
218
219
220
...
223
224
225
226
227
228
229
230

231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
	self.sz = sz
	self.debris = [&m.pool](b)
	self.debris.storage = nil
	return self
end

terra m.pool:free(): {}

	if self.storage == nil then return end
	if self.debris.storage ~= nil then self.debris:free() end
	m.heapf(self.debris) -- storage + debris field allocated in one block
	self.storage = nil
	self.cursor = nil
	self.sz = 0
	self.debris = nil
................................................................................
terra m.pool:clear()
	if self.debris.storage ~= nil then self.debris:free() end
	self.cursor = self.storage
	return self
end

terra m.pool:alloc_bytes(sz: intptr): &opaque
	var space: intptr = self.sz - ([&uint8](self.cursor) - [&uint8](self.storage))

	if space < sz then

		self:cue(self.sz + sz + 256) end
	var ptr = self.cursor
	self.cursor = [&opaque]([&uint8](self.cursor) + sz)
	return ptr
end

terra m.pool:realloc_bytes(oldptr: &opaque, oldsz: intptr, newsz: intptr): &opaque
	var space: intptr = self.sz - ([&uint8](self.cursor) - [&uint8](self.storage))
	var cur = [&uint8](self.cursor)
	if cur - [&uint8](oldptr) == oldsz and newsz - oldsz < space then
		lib.dbg('moving pool cursor')
		cur = cur + (newsz - oldsz)
		self.cursor = [&opaque](cur)
		return oldptr
	else