jobtalle / pool Goto Github PK
View Code? Open in Web Editor NEWA generic C memory pool
License: BSD 3-Clause "New" or "Revised" License
A generic C memory pool
License: BSD 3-Clause "New" or "Revised" License
Is this thread safe?
I have take a deep look at the source, but I still cannot understand, why poolFreed structure can be used to store the freed memory address ? the structure only have a *nextFree element which mean it is just an empty list, how can you store the memory pool address in the structure , I don't understand the deep meaning , please help me, thanks ?
typedef struct poolFreed{
struct poolFreed *nextFree;
} poolFreed;
void poolFree(pool *p, void *ptr)
{
poolFreed *pFreed = p->freed;
p->freed = ptr;
p->freed->nextFree = pFreed;
}
To verify this usage, but it cannot workout, sample test code as below, it would cause SIGSEGV, what's the difference between this and the sample code?
#include <stdio.h>
#include <stdlib.h>
typedef struct list{
struct list *next;
} list;
void insert(list *l, void *ptr)
{
list *p = l;
l = ptr;
l->next = p;
}
int main()
{
list root;
//int i = 10;
//char c = 'a';
//double d = 100.00;
char *i = malloc(100);
char *c = malloc(100);
char *d = malloc(100);
printf("i=%p,c=%p,d=%p\n", &i, &c, &d);
insert(&root, i);
insert(&root, c);
insert(&root, d);
list *l = &root;
while (l)
{
printf("list= %p\n", l);
l = l->next;
}
}
Hi, thanks for sharing this repo. I read the code and just don't understand this API:
Line 25 in 05b7492
void *poolMalloc(pool *p);
What I expect is something like:
void* poolMalloc(pool*p, size_t size);
which can be called, as replacement of malloc like this:
int* data = (int*)malloc(100*sizeof(int)); // before
int* data = (int*)poolMalloc(p, 100*sizeof(int)); // after
a interrupt can cause some issues
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.