Computer Science > STUDY GUIDE > University of British Columbia CPSC 213 implicit.c (All)
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "implicit.h" /* * Determine whether or not a block is in use. */ static int block_is_in_use(void *block_start) { return 1 & ... *((int *) block_start); } /* * Return the size of a block. */ static int get_block_size(void *block_start) { int *header = block_start; // This is equivalent to the value of the header, but setting the // last two bits to 0 (i.e., the value of the header without the // "in-use" bit). return -HEADER_SIZE & *header; } /* * Return the size of the payload of a block. */ static int get_payload_size(void *block_start) { return get_block_size(block_start) - HEADER_SIZE * 2; } /* * Find the start of the block, given a pointer to the payload. */ static void *get_block_start(void *payload) { return payload - HEADER_SIZE; } /* * Find the payload, given a pointer to the start of the block. */ static void *get_payload(void *block_start) { return block_start + HEADER_SIZE; } /* * Set the size of a block, and whether or not it is in use. Remember * each block has two copies of the header (one at each end). */ static void set_block_header(void *block_start, int block_size, int in_use) { int header_value = block_size | in_use; int *header_position = block_start; int *trailer_position = block_start + block_size - HEADER_SIZE; *header_position = header_value; *trailer_position = header_value; [Show More]
Last updated: 2 years ago
Preview 1 out of 4 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
May 28, 2021
Number of pages
4
Written in
This document has been written for:
Uploaded
May 28, 2021
Downloads
0
Views
53
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·