Пример #1
0
void *malloc(size_t size) {
	if ( heap==NULL ) { heap_init(DEFAULT_MAX_HEAP_SIZE); }
	if (freelist == NULL) {
		return NULL; // out of heap
	}
	uint32_t n = (uint32_t) size & SIZEMASK;
	n = (uint32_t) align_to_word_boundary(size_with_header(n));
	Free_Header *chunk = nextfree(n);
	Busy_Header *b = (Busy_Header *) chunk;
	b->size |= BUSY_BIT; // get busy! turn on busy bit at top of size field
	return b;
}
Пример #2
0
static struct BOARD *
bsave(void)
{
    int i;			/* index */
    struct BOARD *now;	/* current position */

    now = nextfree();	/* get free BOARD */

    /* store position */
    for (i = 0; i < 26; i++)
        now->b_board[i] = board[i];
    now->b_in[0] = in[0];
    now->b_in[1] = in[1];
    now->b_off[0] = off[0];
    now->b_off[1] = off[1];
    for (i = 0; i < mvlim; i++) {
        now->b_st[i] = p[i];
        now->b_fn[i] = g[i];
    }
    return (now);
}