add TKMEM_INIT

This commit is contained in:
xianjimli 2018-05-04 11:45:09 +08:00
parent be2f85e685
commit 064cd18eaf
8 changed files with 16 additions and 12 deletions

View File

@ -41,6 +41,7 @@ mem_stat_t mem_stat(void);
void mem_info_dump(void);
#ifdef HAS_STD_MALLOC
#define TKMEM_INIT(size)
#define TKMEM_ALLOC(size) malloc(size)
#define TKMEM_ZALLOC(type) (type*)calloc(1, sizeof(type))
#define TKMEM_ZALLOCN(type, n) (type*)calloc(n, sizeof(type))
@ -52,6 +53,12 @@ void* tk_realloc(void* ptr, uint32_t size);
void tk_free(void* ptr);
void* tk_alloc(uint32_t size);
#define TKMEM_INIT(size) \
{ \
static uint32_t s_heap_mem[size >> 2]; \
mem_init(s_heap_mem, sizeof(s_heap_mem)); \
}
#define TKMEM_ALLOC(size) tk_alloc(size)
#define TKMEM_ZALLOC(type) (type*)tk_calloc(1, sizeof(type))
#define TKMEM_ZALLOCN(type, n) (type*)tk_calloc(n, sizeof(type))

View File

@ -35,8 +35,7 @@ int main(int argc, char** argv) {
const char* str_filename = NULL;
const char* output_filename = NULL;
static uint32_t s_heap_mem[1024 * 1024];
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024);
if (argc != 5) {
printf("Usage: %s ttf_filename str_filename output_filename font_size\n", argv[0]);

View File

@ -33,8 +33,7 @@ int main(int argc, char** argv) {
const char* out_filename = NULL;
image_loader_t* loader = NULL;
static uint32_t s_heap_mem[1024 * 1024];
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024);
if (argc != 3) {
printf("Usage: %s in_filename out_filename\n", argv[0]);

View File

@ -23,14 +23,13 @@
#include "common/utils.h"
#include "base/resource_manager.h"
static uint32_t s_heap_mem[4 * 1024 * 1024];
int main(int argc, char** argv) {
uint32_t size = 0;
uint8_t* input_buff = NULL;
const char* input_filename = NULL;
const char* output_filename = NULL;
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024);
if (argc != 3) {
printf("Usage: %s input_filename output_filename\n", argv[0]);

View File

@ -7,6 +7,7 @@ LIB_DIR=os.environ['LIB_DIR'];
env.Library(os.path.join(LIB_DIR, 'theme_gen'), ['theme_gen.cc', 'xml_theme_gen.cc'])
env['LIBS'] = ['theme_gen', 'common'] + env['LIBS'];
env.Program(os.path.join(BIN_DIR, 'themegen'), ['main.cc'])

View File

@ -24,9 +24,8 @@
int main(int argc, char* argv[]) {
bool_t output_bin = argc > 3;
static uint32_t s_heap_mem[1024 * 1024];
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024)
if (argc < 3) {
printf("Usage: %s input output [bin]\n", argv[0]);

View File

@ -265,8 +265,8 @@ bool qt_to_xml(const char* input_file, const char* output_file) {
int main(int argc, char** argv) {
const char* in_filename = NULL;
const char* out_filename = NULL;
static uint32_t s_heap_mem[1024 * 1024];
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024);
if (argc != 3) {
printf("Usage: %s in_filename out_filename\n", argv[0]);

View File

@ -35,8 +35,8 @@ int main(int argc, char** argv) {
const char* out_filename = NULL;
ui_loader_t* loader = xml_ui_loader();
ui_builder_t* builder = ui_builder_writer(wbuffer_init(&wbuffer, data, sizeof(data)));
static uint32_t s_heap_mem[1024 * 1024];
mem_init(s_heap_mem, sizeof(s_heap_mem));
TKMEM_INIT(4 * 1024 * 1024);
if (argc < 3) {
printf("Usage: %s in_filename out_filename [bin]\n", argv[0]);