static GstMemory* gst_allocator_fast_malloc_alloc(GstAllocator* allocator, gsize size, GstAllocationParams* params) { ASSERT(G_TYPE_CHECK_INSTANCE_TYPE(allocator, gst_allocator_fast_malloc_get_type())); // alignment should be a (power-of-two - 1). gsize alignment = params->align | gst_memory_alignment; ASSERT(!((alignment + 1) & alignment)); gsize headerSize = (sizeof(GstMemoryFastMalloc) + alignment) & ~alignment; gsize allocationSize = params->prefix + size + params->padding; GstMemoryFastMalloc* mem = static_cast<GstMemoryFastMalloc*>(fastAlignedMalloc(alignment + 1, headerSize + allocationSize)); if (!mem) return nullptr; mem->data = reinterpret_cast<uint8_t*>(mem) + headerSize; if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED)) std::memset(mem->data, 0, params->prefix); if (params->padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED)) std::memset(mem->data + params->prefix + size, 0, params->padding); gst_memory_init(GST_MEMORY_CAST(mem), params->flags, allocator, nullptr, allocationSize, alignment, params->prefix, size); return GST_MEMORY_CAST(mem); }
static GstMemoryFastMalloc* gst_allocator_fast_malloc_mem_copy(GstMemoryFastMalloc* mem, gssize offset, gsize size) { gsize alignment = mem->base.align | gst_memory_alignment; ASSERT(!((alignment + 1) & alignment)); gsize headerSize = (sizeof(GstMemoryFastMalloc) + alignment) & ~alignment; gsize allocationSize = size; if (allocationSize == static_cast<gsize>(-1)) { allocationSize = 0; if (offset < 0 || (mem->base.size > static_cast<gsize>(offset))) allocationSize = mem->base.size - offset; } GstMemoryFastMalloc* copy = static_cast<GstMemoryFastMalloc*>(fastAlignedMalloc(alignment + 1, headerSize + allocationSize)); if (!copy) return nullptr; gst_memory_init(GST_MEMORY_CAST(copy), static_cast<GstMemoryFlags>(0), mem->base.allocator, nullptr, allocationSize, alignment, 0, allocationSize); copy->data = reinterpret_cast<uint8_t*>(copy) + headerSize; std::memcpy(copy->data, mem->data + mem->base.offset + offset, allocationSize); return copy; }
CopiedBlock* CopiedBlock::createNoZeroFill(size_t capacity) { if (computeBalance) { balance++; if (!(balance % 10)) dataLog("CopiedBlock Balance: ", balance, "\n"); } return new(NotNull, fastAlignedMalloc(CopiedBlock::blockSize, capacity)) CopiedBlock(capacity); }
Ref<BumpArena::Block> BumpArena::Block::create(BumpArena& arena, size_t capacity) { return adoptRef(*new (NotNull, fastAlignedMalloc(blockSize, sizeof(Block) + capacity)) Block(arena)); }