[sdf] Only track memory in debug mode.

* src/sdf/ftsdf.c (*): Disable total memory
  usage tracking if the program is not in
  debug mode.
This commit is contained in:
Anuj Verma 2020-07-18 16:32:14 +05:30 committed by anujverma
parent c09257f0dd
commit e78016b46d
2 changed files with 41 additions and 10 deletions

View File

@ -1,3 +1,11 @@
2020-07-18 Anuj Verma <anujv@iitbhilai.ac.in>
[sdf] Only track memory in debug mode.
* src/sdf/ftsdf.c (*): Disable total memory
usage tracking if the program is not in
debug mode.
2020-07-18 Anuj Verma <anujv@iitbhilai.ac.in>
[sdfb] Removed Module.

View File

@ -12,6 +12,8 @@
*
*/
#ifdef FT_DEBUG_LEVEL_TRACE
/* To be used with `FT_Memory::user' in order to track */
/* memory allocations. */
typedef struct SDF_MemoryUser_
@ -53,7 +55,33 @@
FT_FREE( ptr ); \
\
memory->user = (void*)current_user; \
} while ( 0 );
} while ( 0 )
#define SDF_MEMORY_TRACKER_DECLARE() SDF_MemoryUser sdf_memory_user
#define SDF_MEMORY_TRACKER_SETUP() \
sdf_memory_user.prev_user = memory->user; \
sdf_memory_user.total_usage = 0; \
memory->user = &sdf_memory_user
#define SDF_MEMORY_TRACKER_DONE() \
memory->user = sdf_memory_user.prev_user; \
FT_TRACE0(( "[sdf] sdf_raster_render: " \
"Total memory used = %ld\n", \
sdf_memory_user.total_usage ))
#else
/* Use the native allocation functions. */
#define SDF_ALLOC FT_QALLOC
#define SDF_FREE FT_FREE
/* Do nothing */
#define SDF_MEMORY_TRACKER_DECLARE()
#define SDF_MEMORY_TRACKER_SETUP()
#define SDF_MEMORY_TRACKER_DONE()
#endif
/**************************************************************************
*
@ -3117,7 +3145,8 @@
FT_Memory memory = NULL;
SDF_Shape* shape = NULL;
SDF_Params internal_params;
SDF_MemoryUser mem_user;
SDF_MEMORY_TRACKER_DECLARE();
/* check for valid arguments */
@ -3182,10 +3211,7 @@
/* also keep a reference of the old user pointer */
/* in order to debug the memory while compiling */
/* with `FT_DEBUG_MEMORY'. */
mem_user.prev_user = memory->user;
mem_user.total_usage = 0;
memory->user = &mem_user;
SDF_MEMORY_TRACKER_SETUP();
FT_CALL( sdf_shape_new( memory, &shape ) );
@ -3213,10 +3239,7 @@
sdf_shape_done( &shape );
/* restore the memory->user */
memory->user = mem_user.prev_user;
FT_TRACE0(( "[sdf] sdf_raster_render: Total memory used = %ld\n",
mem_user.total_usage ));
SDF_MEMORY_TRACKER_DONE();
Exit:
return error;