Improve documentation

The Cosmo API documentation page is pretty good now
https://justine.lol/cosmopolitan/documentation.html
This commit is contained in:
Justine Tunney 2020-12-27 07:02:35 -08:00
parent 13437dd19b
commit 1bc3a25505
367 changed files with 2542 additions and 26178 deletions

View file

@ -146,20 +146,20 @@ static void **ialloc(mstate m, size_t n_elements, size_t *sizes, int opts,
* but the number is not known at compile time, and some of the nodes
* may later need to be freed. For example:
*
* struct Node { int item; struct Node* next; };
* struct Node* build_list() {
* struct Node **pool;
* int n = read_number_of_nodes_needed();
* if (n <= 0) return 0;
* pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
* if (pool == 0) __die();
* // organize into a linked list...
* struct Node* first = pool[0];
* for (i = 0; i < n-1; ++i)
* pool[i]->next = pool[i+1];
* free(pool); * // Can now free the array (or not, if it is needed later)
* return first;
* }
* struct Node { int item; struct Node* next; };
* struct Node* build_list() {
* struct Node **pool;
* int n = read_number_of_nodes_needed();
* if (n <= 0) return 0;
* pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
* if (pool == 0) __die();
* // organize into a linked list...
* struct Node* first = pool[0];
* for (i = 0; i < n-1; ++i)
* pool[i]->next = pool[i+1];
* free(pool); * // Can now free the array (or not, if it is needed later)
* return first;
* }
*/
void **dlindependent_calloc(size_t n_elements, size_t elem_size,
void *chunks[]) {
@ -199,19 +199,18 @@ void **dlindependent_calloc(size_t n_elements, size_t elem_size,
* where several structs or objects must always be allocated at the
* same time. For example:
*
* struct Head { ... }
* struct Foot { ... }
*
* void send_message(char* msg) {
* int msglen = strlen(msg);
* size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
* void* chunks[3];
* if (independent_comalloc(3, sizes, chunks) == 0) __die();
* struct Head* head = (struct Head*)(chunks[0]);
* char* body = (char*)(chunks[1]);
* struct Foot* foot = (struct Foot*)(chunks[2]);
* // ...
* }
* struct Head { ... }
* struct Foot { ... }
* void send_message(char* msg) {
* int msglen = strlen(msg);
* size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
* void* chunks[3];
* if (independent_comalloc(3, sizes, chunks) == 0) __die();
* struct Head* head = (struct Head*)(chunks[0]);
* char* body = (char*)(chunks[1]);
* struct Foot* foot = (struct Foot*)(chunks[2]);
* // ...
* }
*
* In general though, independent_comalloc is worth using only for
* larger values of n_elements. For small values, you probably won't

View file

@ -1,5 +1,5 @@
#include "libc/bits/initializer.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/sysinfo.h"
#include "libc/dce.h"
@ -21,8 +21,8 @@ STATIC_YOINK("_init_dlmalloc");
#define OOM_WARNING "warning: running out of physical memory\n"
#define is_global(M) ((M) == g_dlmalloc)
struct MallocState g_dlmalloc[1];
struct MallocParams g_mparams;
hidden struct MallocState g_dlmalloc[1];
hidden struct MallocParams g_mparams;
/**
* Acquires more system memory for dlmalloc.

View file

@ -3,7 +3,7 @@
/**
* If possible, gives memory back to the system (via negative arguments
* to sbrk) if there is unused memory at the `high' end of the malloc
* to sbrk) if there is unused memory at the `high` end of the malloc
* pool or in unused MMAP segments. You can call this after freeing
* large blocks of memory to potentially reduce the system-level memory
* requirements of a program. However, it cannot guarantee to reduce
@ -11,7 +11,7 @@
* memory will be locked between two used chunks, so they cannot be
* given back to the system.
*
* The `pad' argument to malloc_trim represents the amount of free
* The `pad` argument to malloc_trim represents the amount of free
* trailing space to leave untrimmed. If this argument is zero, only the
* minimum amount of memory to maintain internal data structures will be
* left. Non-zero arguments can be supplied to maintain enough trailing

View file

@ -13,10 +13,10 @@
* use in this malloc, so setting them has no effect. But this malloc
* also supports other options in mallopt:
*
* Symbol param # default allowed param values
* M_TRIM_THRESHOLD -1 2*1024*1024 any (-1U disables trimming)
* M_GRANULARITY -2 page size any power of 2 >= page size
* M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)
* Symbol param # default allowed param values
* M_TRIM_THRESHOLD -1 2*1024*1024 any (-1U disables trimming)
* M_GRANULARITY -2 page size any power of 2 >= page size
* M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)
*/
bool32 mallopt(int param_number, int value) {
size_t val;