/* * Pure Data Packet header file: memory allocation * Copyright (c) by Tom Schouten * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifndef _PF_MEM_H_ #define _PF_MEM_H_ #include #include #include //#define PF_ALLOC_DEBUG // this defines pf_check_all_chunks() #define PF_FASTALLOC // use fast allocator /** @file mem.h @brief Memory allocation The fastalloc is not really fast yet, but at least there's a hook that's working atm. Should be lock-free. This is entirely in the no-gc theme: container elements in libpf (pf_list_t and pf_atom_t) are everywhere and are alloced and freed a lot (each stack operation). Therefore they are re-used as soon as possible using a free stack. The memory used for container elements is never freed, and in the current implementation it even can't be freed. For most applications this is not a problem (there's a stable working set). If you run into problems with this, you're probably using the wrong tool. */ /* a wrapper around malloc and free to keep track of pf's memory usage */ void *pf_alloc(int size); ///< like malloc void pf_dealloc(void *stuff); ///< like free void *pf_realloc(void *stuff, int size); ///< like realloc #endif