feat: rcmem
This commit is contained in:
35
app/rc.c
Normal file
35
app/rc.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <c-libs/rcmem.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void do_stuff(char *rc_s) { printf("Ptr %p -> %s\n", rc_s, rc_s); }
|
||||
|
||||
char *mk_rc_str(const char *s) {
|
||||
char *rc_s = rc_new(20);
|
||||
strncpy(rc_s, s, 20);
|
||||
return rc_s;
|
||||
}
|
||||
|
||||
void rc_info(void *rc) { printf("RC: %d, WRC: %d\n", rc_rc(rc), rc_wrc(rc)); }
|
||||
|
||||
static char *global_rc_s;
|
||||
|
||||
int main() {
|
||||
char *rc_s = mk_rc_str("Hello World!");
|
||||
|
||||
global_rc_s = rc_ref(rc_s);
|
||||
rc_info(rc_s);
|
||||
rc_unref(rc_s);
|
||||
rc_info(global_rc_s);
|
||||
|
||||
do_stuff(global_rc_s);
|
||||
|
||||
global_rc_s = rc_realloc(global_rc_s, 20480);
|
||||
memset(global_rc_s, 'A', 20480);
|
||||
global_rc_s[50] = '\0';
|
||||
do_stuff(global_rc_s);
|
||||
|
||||
rc_unref(global_rc_s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user