CK_ARRAY_INIT(3)

πŸ’– CK_ARRAY_INIT(3) β€” the one where you birth a pointer array πŸ’–

okay bestie, listen. this is ck_array_init from the Concurrency Kit, and yes she's a libck girlie β€” you link her with -lck. πŸŽ€


✨ NAME ✨

ck_array_init β€” initialize a pointer array. that's it. that's the whole job. she sets it up so you can play. πŸ¦‹


πŸ“š LIBRARY πŸ“š

Concurrency Kit (libck, -lck) β€” so like, remember to actually link the library, no cap. πŸ”₯


🌸 SYNOPSIS 🌸

#include <ck_array.h>

bool
ck_array_init(ck_array_t *array, unsigned int mode,
    struct ck_malloc *allocator, unsigned int initial_length);

look at her. four arguments. iconic behavior. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

so ck_array_init(3) initializes the array that array points at. like, that's her whole thing, she takes the pointer you hand her and makes it a real, functional array. periodt. ✨

the mode value must be CK_ARRAY_MODE_SPMC β€” no other mode, don't try it, she will not entertain you. πŸ™ˆ

the allocator argument must point to a ck_malloc data structure where the function pointers for malloc, free and realloc are all initialized and non-NULL. all three. every single one. if you leave one NULL it's giving chaos and we don't do that here. πŸ’€

and initial_length? that specifies the initial length of the array. and here's the vibe check: the value of initial_length must be greater than or equal to 2. lowkey non-negotiable. πŸ“

now the slay part: an array allows for one concurrent put or remove operation in the presence of any number of concurrent CK_ARRAY_FOREACH operations. yes bestie, ONE writer-adjacent operation while literally unlimited foreach operations run alongside it. that's the whole flex. 🌈


🫢 RETURN VALUES 🫢

  • returns true if the array was successfully created πŸ’–
  • returns false if the creation failed 😭

and when does it fail? failure may occur due to internal memory allocation failures, or because you passed invalid arguments. (so like, read the DESCRIPTION again if you got a false. she told you. πŸ‘€)


⭐ SEE ALSO ⭐

additional information available at http://concurrencykit.org/ β€” go read it, iykyk πŸ“–βœ¨


and that's the page bestie!! this whole thing is from the CK_ARRAY_INIT(3) manual page, dated October 18, 2013. she's been serving since 2013 and she has not missed a day. mwah πŸ’‹πŸ’œ

πŸ“¦ where this page comes from