MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / alloc

Method alloc

cranelift/entity/src/list.rs:193–212  ·  view source on GitHub ↗

Allocate a storage block with a size given by `sclass`. Returns the first index of an available segment of `self.data` containing `sclass_size(sclass)` elements. The allocated memory is filled with reserved values.

(&mut self, sclass: SizeClass)

Source from the content-addressed store, hash-verified

191 /// `sclass_size(sclass)` elements. The allocated memory is filled with reserved
192 /// values.
193 fn alloc(&mut self, sclass: SizeClass) -> usize {
194 // First try the free list for this size class.
195 match self.free.get(sclass as usize).cloned() {
196 Some(head) if head > 0 => {
197 // The free list pointers are offset by 1, using 0 to terminate the list.
198 // A block on the free list has two entries: `[ 0, next ]`.
199 // The 0 is where the length field would be stored for a block in use.
200 // The free list heads and the next pointer point at the `next` field.
201 self.free[sclass as usize] = self.data[head].index();
202 head - 1
203 }
204 _ => {
205 // Nothing on the free list. Allocate more memory.
206 let offset = self.data.len();
207 self.data
208 .resize(offset + sclass_size(sclass), T::reserved_value());
209 offset
210 }
211 }
212 }
213
214 /// Free a storage block with a size given by `sclass`.
215 ///

Callers 6

reallocMethod · 0.45
from_sliceMethod · 0.45
deep_cloneMethod · 0.45
pushMethod · 0.45
growMethod · 0.45
block_allocatorFunction · 0.45

Calls 5

sclass_sizeFunction · 0.85
getMethod · 0.45
indexMethod · 0.45
lenMethod · 0.45
resizeMethod · 0.45

Tested by 1

block_allocatorFunction · 0.36