comparison projects/heavy/hello-world/MessagePool.h @ 160:5bcf04234f80 heavy-updated

- added -std=c99 to Makefile for user-supplied C files (required for heavy files) - changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff) - use build_pd.sh to compile and run pd files (-h for usage instructions)
author chnrx <chris.heinrichs@gmail.com>
date Thu, 05 Nov 2015 18:58:26 +0000
parents
children
comparison
equal deleted inserted replaced
159:1e7db6610600 160:5bcf04234f80
1 /**
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef _MESSAGE_POOL_H_
18 #define _MESSAGE_POOL_H_
19
20 #include "Utils.h"
21
22 struct HvMessage;
23
24 #define MP_NUM_MESSAGE_LISTS 4
25
26 typedef struct MessagePoolList {
27 struct MessageListNode *head; // list of currently available blocks
28 struct MessageListNode *pool; // list of currently used blocks
29 } MessagePoolList;
30
31 typedef struct MessagePool {
32 char *buffer; // the buffer of all messages
33 hv_size_t bufferSize; // in bytes
34 hv_size_t bufferIndex; // the number of total reserved bytes
35
36 MessagePoolList lists[MP_NUM_MESSAGE_LISTS];
37 } MessagePool;
38
39 /**
40 * The MessagePool is a basic memory management system. It reserves a large block of memory at initialisation
41 * and proceeds to divide this block into smaller chunks (usually 512 bytes) as they are needed. These chunks are
42 * further divided into 32, 64, 128, or 256 sections. Each of these sections is managed by a MessagePoolList (MPL).
43 * An MPL is a linked-list data structure which is initialised such that its own pool of listnodes is filled with nodes
44 * that point at each subblock (e.g. each 32-byte block of a 512-block chunk).
45 *
46 * MessagePool is loosely inspired by TCMalloc. http://goog-perftools.sourceforge.net/doc/tcmalloc.html
47 */
48
49 hv_size_t mp_init(struct MessagePool *mp, hv_size_t numKB);
50
51 void mp_free(struct MessagePool *mp);
52
53 /**
54 * Adds a message to the pool and returns a pointer to the copy. Returns NULL
55 * if no space was available in the pool.
56 */
57 struct HvMessage *mp_addMessage(struct MessagePool *mp, const struct HvMessage *m);
58
59 void mp_freeMessage(struct MessagePool *mp, struct HvMessage *m);
60
61 #endif // _MESSAGE_POOL_H_