diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | c90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch) | |
tree | 6d8391395bce9eaea4ad78958617edb20c6a7573 /kpat/freecell-solver/alloc.h | |
download | tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpat/freecell-solver/alloc.h')
-rw-r--r-- | kpat/freecell-solver/alloc.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/kpat/freecell-solver/alloc.h b/kpat/freecell-solver/alloc.h new file mode 100644 index 00000000..5b339f24 --- /dev/null +++ b/kpat/freecell-solver/alloc.h @@ -0,0 +1,86 @@ + +#ifndef FC_SOLVE__ALLOC_H +#define FC_SOLVE__ALLOC_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + +struct fcs_compact_allocator_struct +{ + char * * packs; + int max_num_packs; + int num_packs; + char * max_ptr; + char * ptr; + char * rollback_ptr; +}; + +typedef struct fcs_compact_allocator_struct fcs_compact_allocator_t; + +extern fcs_compact_allocator_t * + freecell_solver_compact_allocator_new(void); + +extern void freecell_solver_compact_allocator_extend( + fcs_compact_allocator_t * allocator + ); +#if 0 +extern char * + freecell_solver_compact_allocator_alloc( + fcs_compact_allocator_t * allocator, + int how_much + ); +#else +#define fcs_compact_alloc_into_var(result,allocator_orig,what_t) \ +{ \ + register fcs_compact_allocator_t * allocator = (allocator_orig); \ + if (allocator->max_ptr - allocator->ptr < sizeof(what_t)) \ + { \ + freecell_solver_compact_allocator_extend(allocator); \ + } \ + allocator->rollback_ptr = allocator->ptr; \ + allocator->ptr += ((sizeof(what_t))+(sizeof(char *)-((sizeof(what_t))&(sizeof(char *)-1)))); \ + result = (what_t *)allocator->rollback_ptr; \ +} + +#define fcs_compact_alloc_typed_ptr_into_var(result, type_t, allocator_orig, how_much_orig) \ +{ \ + register fcs_compact_allocator_t * allocator = (allocator_orig); \ + register int how_much = (how_much_orig); \ + if (allocator->max_ptr - allocator->ptr < how_much) \ + { \ + freecell_solver_compact_allocator_extend(allocator); \ + } \ + allocator->rollback_ptr = allocator->ptr; \ + /* Round ptr to the next pointer boundary */ \ + allocator->ptr += ((how_much)+((sizeof(char *)-((how_much)&(sizeof(char *)-1)))&(sizeof(char*)-1))); \ + result = (type_t *)allocator->rollback_ptr; \ +} + +#endif + +#if 0 +extern void freecell_solver_compact_allocator_release(fcs_compact_allocator_t * allocator); +#else +#define fcs_compact_alloc_release(allocator) \ +{ \ + (allocator)->ptr = (allocator)->rollback_ptr; \ +} +#endif + +extern void freecell_solver_compact_allocator_finish(fcs_compact_allocator_t * allocator); + +extern void freecell_solver_compact_allocator_foreach( + fcs_compact_allocator_t * allocator, + int data_width, + void (*ptr_function)(void *, void *), + void * context + ); + +#ifdef __cplusplus +}; +#endif + +#endif |