Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:ClickHouse ClickHouse Unaligned

From Leeroopedia
Revision as of 14:38, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/ClickHouse_ClickHouse_Unaligned.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Memory, Performance
Last Updated 2026-02-08 00:00 GMT

Overview

Safe unaligned memory access functions for reading and writing data.

Description

Provides unalignedLoad/Store functions that work correctly even when addresses aren't aligned, using memcpy to avoid UB.

Usage

Use when reading/writing data at arbitrary memory locations, parsing binary formats, or implementing serialization.

Code Reference

Source Location

Signature

template <typename T>
inline T unalignedLoad(const void * address);

template <typename T>
inline void unalignedStore(void * address, const typename std::enable_if<true, T>::type & src);

template <std::endian endian, typename T>
inline T unalignedLoadEndian(const void * address);

template <std::endian endian, typename T>
inline void unalignedStoreEndian(void * address, T & src);

template <typename T>
inline T unalignedLoadLittleEndian(const void * address);

template <typename T>
inline void unalignedStoreLittleEndian(void * address, const typename std::enable_if<true, T>::type & src);

Import

#include <base/unaligned.h>

Usage Examples

#include <base/unaligned.h>

char buffer[100];
char* ptr = buffer + 1;  // Misaligned

// Safe unaligned access
uint64_t value = unalignedLoad<uint64_t>(ptr);
unalignedStore<uint32_t>(ptr + 8, 12345);

// Endian-specific loads
uint32_t le = unalignedLoadLittleEndian<uint32_t>(ptr);
uint32_t be = unalignedLoadBigEndian<uint32_t>(ptr);

// Store with endianness
unalignedStoreLittleEndian<uint64_t>(ptr, 0x123456789ABCDEF0ULL);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment