MEMSWAP(3pub)
π
MEMSWAP β like, the 3pub manual page, bestie
okay so welcome to publib's very own memswap, straight out of the C Programmer's Manual. sit down, grab a strawberry π, and let's swap some memory. no cap.
β¨ NAME β¨
memswap β swap the contents of two memory blocks π
π¦ SYNOPSIS π¦
#include <publib.h>
void memswap(void *block1, void *block2, size_t n);
πΈ DESCRIPTION πΈ
so basically memswap takes the two blocks that your first two args point at and swaps their contents. that's it, that's the whole vibe. the last argument, n, tells it how big those memory blocks are. periodt.
π EXAMPLE π
say you wanna swap two structs (iconic behaviour honestly), you'd do this:
struct tm tm1, tm2;
memswap(&tm1, &tm2, sizeof(struct tm));
π BUGS π
okay bestie, real talk, there are caveats:
- using
memswapto swap small portions of memory is inefficient. it is not worth it to use it to swap variables of any of the basic types, for instance β for those cases, just use inline code, fr fr. however, for large portions of memory, e.g., arrays, it is convenient. so like, know your lane. π memswapcan't swap variables whose address can't be taken. this excludes variables with theregisterspecifier and bitfields in structs. but then, there is no way to write a function (or macro) that can handle any kind of arguments. life is hard. π
ngl the "life is hard" thing is literally in the original and honestly? the author ate with that one.
π₯ SEE ALSO π₯
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi)
and that's the whole page, angel π«Ά this lil' number lives in Publib's C Programmer's Manual, so if you ever forget it, that's where to find it. go forth and swap responsibly β¨π
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms