|
From: <ms...@mo...> - 2002-12-30 10:49:28
|
The following patch silences a small batch of warnings about
comparison always true/false in src/sc2code/libs/memory/w_memlib.c.
MEM_HANDLE is a signed short, MAX_EXTENTS was larger than a signed short
can be (100000) so anytime comparisons happened between MEM_HANDLEs and
MAX_EXTENTS this warning was generated.
MAX_EXTENTS is an upper limit on how many memory chunks can allocated
at a time...
TTFN,
Mike
ps:
MEM_HANDLE should probably be an unsigned short, and then all of the
h > 0 tests would have to be nuked... since negative values don't
appear to be used, this would double the number of chunks available.
pps:
since the extents array is static and 20 bytes per element this patch
lowers the runtime memory usage of the program by about 1.3 Megs. I've
not done any tests to see how small the array can safely be sized...
but would be willing to write code to dynamically increase the size
of the extent array as it is needed, so that it can be started very
very small and grow. I'd need to know this would be desired by
whoever controls memlib...
Basically code involved looks like this:
====
mem_simple_access(MEM_HANDLE h)
{
if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h)
====
Types:
====
src/sc2code/libs/memlib.h:typedef SWORD MEM_HANDLE;
src/sc2code/libs/compiler.h:typedef signed short SWORD;
====
Warnings looked like such:
====
gcc -o obj/debug/./src/sc2code/libs/memory/w_memlib.o -c -I/usr/include/SDL -D_REENTRANT -I/usr/include/SDL -D_REENTRANT -g -O0 -DGFXMODULE_SDL -DSOUNDMODULE_SDL -I/usr/include/SDL -D_REENTRANT -I/home/msimons/local/sdl/include -DHAVE_CONFIG_H -I src -I src/sc2code -I src/sc2code/libs src/sc2code/libs/memory/w_memlib.c
src/sc2code/libs/memory/w_memlib.c: In function `mem_get_size':
src/sc2code/libs/memory/w_memlib.c:346: warning: comparison is always true due to limited range of data type
src/sc2code/libs/memory/w_memlib.c: In function `mem_release':
src/sc2code/libs/memory/w_memlib.c:485: warning: comparison is always false due to limited range of data type
src/sc2code/libs/memory/w_memlib.c: In function `mem_simple_access':
src/sc2code/libs/memory/w_memlib.c:540: warning: comparison is always true due to limited range of data type
src/sc2code/libs/memory/w_memlib.c: In function `mem_simple_unaccess':
src/sc2code/libs/memory/w_memlib.c:578: warning: comparison is always true due to limited range of data type
====
Index: ./src/sc2code/libs/memory/w_memlib.c
===================================================================
RCS file: /cvsroot/sc2/sc2/src/sc2code/libs/memory/w_memlib.c,v
retrieving revision 1.7
diff -u -p -r1.7 w_memlib.c
--- ./src/sc2code/libs/memory/w_memlib.c 23 Dec 2002 02:27:06 -0000 1.7
+++ ./src/sc2code/libs/memory/w_memlib.c 30 Dec 2002 10:29:01 -0000
@@ -45,7 +45,7 @@ int leak_size = -1;
#endif
Semaphore _MemorySem;
-#define MAX_EXTENTS 100000
+#define MAX_EXTENTS 32000
/* Keep track of memory allocations. */
|