[svn:parrot] r47461 - branches/gc_massacre/src/gc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Jun 8 11:42:15 UTC 2010
Author: bacek
Date: Tue Jun 8 11:42:15 2010
New Revision: 47461
URL: https://trac.parrot.org/parrot/changeset/47461
Log:
Implement Fixed_Allocator (not tested)
Modified:
branches/gc_massacre/src/gc/fixed_allocator.c
branches/gc_massacre/src/gc/fixed_allocator.h
Modified: branches/gc_massacre/src/gc/fixed_allocator.c
==============================================================================
--- branches/gc_massacre/src/gc/fixed_allocator.c Tue Jun 8 11:41:12 2010 (r47460)
+++ branches/gc_massacre/src/gc/fixed_allocator.c Tue Jun 8 11:42:15 2010 (r47461)
@@ -39,12 +39,12 @@
Destroy Fixed_Allocator.
=item C<void* Parrot_gc_fixed_allocator_allocate(PARROT_INTERP, Fixed_Allocator
-*, size_t size)>
+*allocator, size_t size)>
Allocate fixed size memory from Fixed_Allocator.
-=item C<void* Parrot_gc_fixed_allocator_free(PARROT_INTERP, Fixed_Allocator *,
-void *data, size_t size)>
+=item C<void Parrot_gc_fixed_allocator_free(PARROT_INTERP, Fixed_Allocator
+*allocator, void *data, size_t size)>
Free fixed size memory from Fixed_Allocator.
@@ -57,7 +57,7 @@
struct Fixed_Allocator*
Parrot_gc_fixed_allocator_new(PARROT_INTERP)
{
- return (struct Fixed_Allocator*) mem_sys_allocate(sizeof (Fixed_Allocator));
+ return mem_internal_allocate_zeroed_typed(Fixed_Allocator);
}
PARROT_EXPORT
@@ -73,15 +73,44 @@
ARGIN(Fixed_Allocator *allocator),
size_t size)
{
+ /* We always align size to 4/8 bytes. */
+ size_t index, alloc_size;
+ void *ret;
+ PARROT_ASSERT(size);
+ index = (size - 1) / sizeof (void*);
+ alloc_size = (index + 1) * sizeof (void *);
+
+ if (index >= allocator->num_pools) {
+ size_t new_size = index + 1;
+ /* (re)allocate pools */
+ if (allocator->num_pools)
+ allocator->pools = mem_internal_realloc_n_zeroed_typed(allocator->pools, new_size, allocator->num_pools, Pool_Allocator*);
+ else
+ allocator->pools = mem_internal_allocate_n_zeroed_typed(new_size, Pool_Allocator*);
+
+ allocator->num_pools = new_size;
+ }
+
+ if (allocator->pools[index] == NULL)
+ allocator->pools[index] = Parrot_gc_create_pool_allocator(alloc_size);
+
+ ret = Parrot_gc_pool_allocate(interp, allocator->pools[index]);
+ //memset(ret, 0, alloc_size);
+ return ret;
}
PARROT_EXPORT
-PARROT_CAN_RETURN_NULL
-void*
+void
Parrot_gc_fixed_allocator_free(PARROT_INTERP,
ARGIN(Fixed_Allocator *allocator),
ARGFREE_NOTNULL(void *data), size_t size)
{
+ /* We always align size to 4/8 bytes. */
+ size_t index = (size - 1) / sizeof (void*);
+
+ PARROT_ASSERT(allocator->pools[index]);
+
+ Parrot_gc_pool_free(allocator->pools[index], data);
}
Modified: branches/gc_massacre/src/gc/fixed_allocator.h
==============================================================================
--- branches/gc_massacre/src/gc/fixed_allocator.h Tue Jun 8 11:41:12 2010 (r47460)
+++ branches/gc_massacre/src/gc/fixed_allocator.h Tue Jun 8 11:42:15 2010 (r47461)
@@ -29,7 +29,7 @@
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
void* Parrot_gc_fixed_allocator_allocate(PARROT_INTERP,
- ARGIN(Fixed_Allocator *),
+ ARGIN(Fixed_Allocator *allocator),
size_t size)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -41,9 +41,8 @@
__attribute__nonnull__(2);
PARROT_EXPORT
-PARROT_CAN_RETURN_NULL
-void* Parrot_gc_fixed_allocator_free(PARROT_INTERP,
- ARGIN(Fixed_Allocator *),
+void Parrot_gc_fixed_allocator_free(PARROT_INTERP,
+ ARGIN(Fixed_Allocator *allocator),
ARGFREE_NOTNULL(void *data),
size_t size)
__attribute__nonnull__(1)
@@ -58,7 +57,7 @@
#define ASSERT_ARGS_Parrot_gc_fixed_allocator_allocate \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(Fixed_Allocator *))
+ , PARROT_ASSERT_ARG(allocator))
#define ASSERT_ARGS_Parrot_gc_fixed_allocator_destroy \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
@@ -66,7 +65,7 @@
#define ASSERT_ARGS_Parrot_gc_fixed_allocator_free \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(Fixed_Allocator *) \
+ , PARROT_ASSERT_ARG(allocator) \
, PARROT_ASSERT_ARG(data))
#define ASSERT_ARGS_Parrot_gc_fixed_allocator_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
More information about the parrot-commits
mailing list