blob: 92af2d2b2fdc13ba9f39f7df42f0f3698fe9adaf [file] [log] [blame]
Benny Prijono7d93d4e2006-09-17 19:54:23 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono7d93d4e2006-09-17 19:54:23 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __POOL_STACK_H__
20#define __POOL_STACK_H__
21
22#include <pj/pool.h>
23
24/**
25 * @defgroup PJ_POOL_BUFFER Stack/Buffer Based Memory Pool Allocator
26 * @ingroup PJ_POOL_GROUP
27 * @brief Stack/buffer based pool.
28 *
29 * This section describes an implementation of memory pool which uses
30 * memory allocated from the stack. Application creates this pool
31 * by specifying a buffer (which can be allocated from static memory or
32 * stack variable), and then use normal pool API to access/use the pool.
33 *
34 * If the buffer specified during pool creation is a buffer located in the
35 * stack, the pool will be invalidated (or implicitly destroyed) when the
36 * execution leaves the enclosing block containing the buffer. Note
37 * that application must make sure that any objects allocated from this
38 * pool (such as mutexes) have been destroyed before the pool gets
39 * invalidated.
40 *
41 * Sample usage:
42 *
43 * \code
44 #include <pjlib.h>
45
46 static void test()
47 {
48 char buffer[500];
49 pj_pool_t *pool;
50 void *p;
51
52 pool = pj_pool_create_on_buf("thepool", buffer, sizeof(buffer));
53
54 // Use the pool as usual
55 p = pj_pool_alloc(pool, ...);
56 ...
57
58 // No need to release the pool
59 }
60
61 int main()
62 {
63 pj_init();
64 test();
65 return 0;
66 }
67
68 \endcode
69 *
70 * @{
71 */
72
73
74/**
75 * Create the pool using the specified buffer as the pool's memory.
76 * Subsequent allocations made from the pool will use the memory from
77 * this buffer.
78 *
79 * If the buffer specified in the parameter is a buffer located in the
80 * stack, the pool will be invalid (or implicitly destroyed) when the
81 * execution leaves the enclosing block containing the buffer. Note
82 * that application must make sure that any objects allocated from this
83 * pool (such as mutexes) have been destroyed before the pool gets
84 * invalidated.
85 *
86 * @param name Optional pool name.
87 * @param buf Buffer to be used by the pool.
88 * @param size The size of the buffer.
89 *
90 * @return The memory pool instance.
91 */
92PJ_DECL(pj_pool_t*) pj_pool_create_on_buf(const char *name,
93 void *buf,
94 pj_size_t size);
95
96/**
97 * @}
98 */
99
100#endif /* __POOL_STACK_H__ */
101