コード例 #1
0
ファイル: OSMem.c プロジェクト: AaronFriel/ghc
void *
osGetMBlocks(uint32_t n) {
    void* ret;
    ret = findFreeBlocks(n);
    if(ret==0) {
        alloc_rec* alloc;
        alloc = allocNew(n);
        /* We already belch in allocNew if it fails */
        if (alloc == 0) {
            stg_exit(EXIT_FAILURE);
        } else {
            insertFree(alloc->base, alloc->size);
            ret = findFreeBlocks(n);
        }
    }

    if(ret!=0) {
        /* (In)sanity tests */
        if (((W_)ret & MBLOCK_MASK) != 0) {
            barf("getMBlocks: misaligned block returned");
        }

        commitBlocks(ret, (W_)MBLOCK_SIZE*n);
    }

    return ret;
}
コード例 #2
0
ファイル: CHspCode.cpp プロジェクト: vain0/hpimod
	/**
	このバッファに書き込んだものにデストラクタは起動されない。
	base に対する alignment を考慮して確保する。その相対位置の整数値 n が返る。
	つまり、&base[n * alignment] == 確保したバッファへのポインタ。
	//*/
	int AlignedPlainStorage::push(size_t size, size_t alignment, void const* _base)
	{
		assert(alignment > 0);
		auto& it = allocNew(size + alignment - 1);

		char* top = it.data();
		auto const base = reinterpret_cast<char const*>(_base);
		int const dif = top - base;
		size_t const padding =
			(dif <= 0)
			? ((-dif) % alignment)
			: (alignment - (dif % alignment)) % alignment;

		top += padding;
		assert((top - base) % alignment == 0 && padding < alignment);
		return (top - base) / alignment;
	}