-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
41 lines (32 loc) · 820 Bytes
/
Copy pathexample.c
File metadata and controls
41 lines (32 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include "pool.h"
typedef struct packet {
char payload[2048];
int length;
} packet_t;
void packet_send(packet_t *pkt)
{
printf("%.*s\n", pkt->length, pkt->payload);
}
int main(void)
{
object_pool_t pool;
if (object_pool_init(&pool, 1024, sizeof(packet_t)) < 0) {
printf("Object pool initialization failed.\n");
return -1;
}
packet_t *packet_p = object_pool_acquire(&pool);
if (packet_p) {
const char *packet_payload = "Hello, World!";
packet_p->length = strlen(packet_payload);
memcpy(packet_p->payload, packet_payload, packet_p->length);
packet_send(packet_p);
object_pool_release(&pool, packet_p);
}
else {
printf("Pool exhausted or allocation failure.\n");
}
object_pool_cleanup(&pool);
return 0;
}