Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function allocate_1(size: uword): (ptr u8, uword) {
- var block_size: uword = size + sizeof(uword);
- var {p, s} = allocate_2(block_size);
- *(p as ptr uword) = block_size;
- return p + sizeof(uword), s - sizeof(uword);
- }
- function reallocate_1(p: ptr u8, new_size: uword): (ptr u8, uword) {
- var block_p: ptr u8 = p - sizeof(uword);
- var block_size: uword = *(block_p as ptr uword);
- var new_block_size: uword = new_size + sizeof(uword);
- var {new_p, new_s} = reallocate_2(block_p, block_size, new_block_size);
- *(new_p as ptr uword) = new_block_size;
- memcpy(new_p + sizeof(uword), p, std::min(block_size - sizeof(uword), new_size));
- return new_p + sizeof(uword), new_s - sizeof(uword);
- }
- function deallocate_1(p: ptr u8) {
- var block_p: ptr u8 = p - sizeof(uword);
- var block_size: uword = *(block_p as ptr uword);
- deallocate_2(block_p, block_size);
- }
- function allocate_2(size: uword): (ptr u8, uword) {
- return allocate_1(size);
- }
- function reallocate_2(p: ptr u8, old_size: uword, new_size: uword): (ptr u8, uword) {
- return reallocate_1(p, new_size);
- }
- function deallocate_2(p: ptr u8, size: uword) {
- return deallocate_1(p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement