1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // --------------------------------------------------------------------------*/
11 * Native memory functions.
16 /* Palm OS Functions. */
17 #if defined(__palmos__)
18 #include <MemoryMgr.h>
24 /** Allocates the given number of bytes. */
25 void* sjme_malloc(sjme_jint size
)
29 /* These will never allocate. */
33 /* Round size and include extra 4-bytes for size storage. */
34 size
= ((size
+ SJME_JINT_C(3)) & (~SJME_JINT_C(3))) + SJME_JINT_C(4);
36 /* Exceeds maximum permitted allocation size? */
37 if (sizeof(sjme_jint
) > sizeof(size_t) && size
> (sjme_jint
)SIZE_MAX
)
40 #if defined(__palmos__)
41 /* Palm OS, use glue to allow greater than 64K. */
42 rv
= MemGluePtrNew(size
);
44 /* Use standard C function otherwise. */
48 /* Did not allocate? */
52 #if defined(__palmos__)
53 /* Clear memory on Palm OS. */
57 /* Store the size into this memory block for later free. */
58 *((sjme_jint
*)rv
) = size
;
60 /* Return the adjusted pointer. */
61 return SJME_POINTER_OFFSET_LONG(rv
, 4);
64 /** Frees the given pointer. */
65 void sjme_free(void* p
)
69 /* Ignore null pointers. */
73 /* Base pointer which is size shifted. */
74 basep
= SJME_POINTER_OFFSET_LONG(p
, -4);
76 #if defined(__palmos__)
77 /* Use Palm OS free. */
80 /* Use Standard C free. */