Skip to content

Instantly share code, notes, and snippets.

@MonocleSecurity
MonocleSecurity / cpp
Last active February 13, 2026 08:58
Aligned memory allocator for std::unique_ptr
#include <memory>
void* AlignedMalloc(const size_t size, const size_t alignment)
{
const size_t offset = alignment - 1 + sizeof(void*);
void* buffer = malloc(size + offset);
void** ptr = reinterpret_cast<void**>((reinterpret_cast<size_t>(buffer) + offset) & ~(alignment - 1));
ptr[-1] = buffer;
return ptr;
}
#!/bin/bash
set -e
##### CHECK PARAMETERS #####
PRODUCTION=0
while [[ "$#" -gt 0 ]]; do
case $1 in
-p|--production) PRODUCTION=1 ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift