From a2a2e14e0d400e1c82b4d02c4399602488578dc6 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Thu, 22 Aug 2013 12:12:47 +0200 Subject: lua: Switch memory allocator from dl to tlsf Instead of providing yet another memory allocator implementation use tlsf and simply link tlsf library. Another small improvement is to *grow* memory pool by grabbing audiobuffer instead of just switching to use audiobuf exclusively. Tested with simple lua 'memory eater' script. This patch extends tlsf lib slightly. You can provide void *get_new_area(size_t * size) function which will override weak dummy implementation provided in lib itself. This allows to automaticaly initialize memory pool as well as grow memory pool if needed (for example grab audiobuffer when pluginbuffer is exhaused). Change-Id: I841af6b6b5bbbf546c14cbf139a7723fbb982f1b --- apps/plugins/lua/rockmalloc.c | 63 ------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 apps/plugins/lua/rockmalloc.c (limited to 'apps/plugins/lua/rockmalloc.c') diff --git a/apps/plugins/lua/rockmalloc.c b/apps/plugins/lua/rockmalloc.c deleted file mode 100644 index 14a4339..0000000 --- a/apps/plugins/lua/rockmalloc.c +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2008 Dan Everton (safetydan) - * - * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "plugin.h" -#include "rockmalloc.h" -#include "malloc.c" - -void *rocklua_morecore(int size) -{ - static char *sbrk_top = NULL; - static ssize_t total_size = 0; - void *ptr = 0; - - if (size > 0) { - size = size + 4 - (size % 4); - - if (sbrk_top == NULL) { - sbrk_top = rb->plugin_get_buffer((size_t *) &total_size); - } - - if (sbrk_top == NULL || size + 4 > abs(total_size)) { - /* Try the audio buffer */ - sbrk_top = rb->plugin_get_audio_buffer((size_t *) &total_size); - - if(sbrk_top == NULL || size + 4 > abs(total_size)) { - printf("malloc failed for %d!\n", size); - return (void *) MFAIL; - } - } - - ptr = sbrk_top + 4; - *((unsigned int *) sbrk_top) = size; - - sbrk_top += size + 4; - total_size -= size + 4; - - return ptr; - } else if (size < 0) { - /* we don't currently support shrink behavior */ - return (void *) MFAIL; - } else { - return sbrk_top; - } -} - -- cgit v1.1