tcp_malloc(3)
π tcp_malloc(3) π
okay bestie so this is the z88dk Programmer's Manual page for tcp_calloc, tcp_malloc and tcp_free β the memory girlies of ZSock. yes it's called tcp_malloc(3) but there's a whole squad in here. let's get into it π«Ά
β¨ NAME β¨
tcp_calloc, tcp_malloc, tcp_free β allocate and free memory π
π SYNOPSIS π
#include <net/misc.h>
void *tcp_calloc(size_t nmemb, size_t size);
void *tcp_malloc(size_t size);
void tcp_free(void *ptr);
πΈ DESCRIPTION πΈ
okay so calloc() grabs memory for an array of nmemb elements, each one size bytes big, and hands you back a pointer to that memory. and the memory? set to zero. squeaky clean, no mystery bytes, we love a fresh start β¨
malloc() grabs size bytes and returns a pointer to the memory it got you. but heads up bestie β the memory is not cleared. whatever was there before is still there. no notes, that's just how it is π«£
free() releases the memory space that ptr points to. and this is the part where you gotta be careful, fr fr: that ptr must have been returned by a previous call to malloc() or calloc(). otherwise, or if free(ptr) already got called before, undefined behaviour occurs π like genuinely, we don't know what happens, it's giving chaos.
one lil mercy tho: if ptr is NULL, no operation is performed. nothing happens. iconic, honestly π
π¦ RETURN VALUES π¦
for calloc() and malloc(): you get back a pointer to the allocated memory β and it's suitably aligned for any kind of variable, which is very generous of it β or NULL if the request fails π
free() returns no value. it just... does the thing. main character, no receipts π
π§ SEE ALSO π§
tcp_pagein(3z)tcp_pageout(3z)
β NOTES β
okay so here's the lore. these functions manipulate memory in a private memory page belonging to ZSock. that page is 16k, and it holds all the buffers that ZSock uses. so yeah β requests for large amounts of memory are likely to fail (and honestly, in any case, they're not recommended). like bestie, it's a 16k page, be reasonable π₯Ί
this facility exists so that daemons can be written simply β they have no address space of their own, so they need a little something. but user applications should not use these facilities. periodt.
and if a user application needs a large amount of memory β like, >256 bytes large β then the application should either be of the BAD type, or it should be redesigned. no cap, that's the rule π
tl;dr: this is daemon territory. if you're a user app, walk away. it's not for you, it's not about you π
π AUTHOR π
Dominic Morris <dom@jb.man.ac.uk>
and that's the whole page, bestie π this was the z88dk Programmer's Manual, tcp_malloc(3), dated February 18 2000 β ancient, but still serving. bye pookie, go align your pointers ππ
π¦ where this page comes from
- fedora 43: z88dk 1.10.1-33.20150709cvs.fc43 Β· ClArtistic
- fedora 44: z88dk 1.10.1-33.20150709cvs.fc43 Β· ClArtistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms