You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/05/31 19:43:02 UTC
svn commit: r410611 - in /webservices/axis2/trunk/c/util:
include/axis2_allocator.h src/allocator.c
Author: samisa
Date: Wed May 31 10:43:01 2006
New Revision: 410611
URL: http://svn.apache.org/viewvc?rev=410611&view=rev
Log:
Added additional parameter, allocator, to the ops of allocator to facilitate the use of a memory pool
Modified:
webservices/axis2/trunk/c/util/include/axis2_allocator.h
webservices/axis2/trunk/c/util/src/allocator.c
Modified: webservices/axis2/trunk/c/util/include/axis2_allocator.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axis2_allocator.h?rev=410611&r1=410610&r2=410611&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axis2_allocator.h (original)
+++ webservices/axis2/trunk/c/util/include/axis2_allocator.h Wed May 31 10:43:01 2006
@@ -49,22 +49,31 @@
/**
* allocates memory
+ * @param allocator pointer to allocator struct. In the default
+ * implementation this is not used, however this parameter is useful
+ * when the allocator implementation is dealing with a memory pool.
* @param size size of the memory block to be allocated
* @return pointer to the allocated memory block
*/
- void * (*malloc) (size_t size);
+ void * (*malloc) (struct axis2_allocator *allocator, size_t size);
/**
* re-llocates memory
+ * @param allocator pointer to allocator struct. In the default
+ * implementation this is not used, however this parameter is useful
+ * when the allocator implementation is dealing with a memory pool.
* @param ptr memory block who's size to be changed
* @param size size of the memory block to be allocated
* @return pointer to the allocated memory block
*/
- void * (*realloc) (void *ptr, size_t size);
+ void * (*realloc) (struct axis2_allocator *allocator, void *ptr, size_t size);
/**
* frees memory
+ * @param allocator pointer to allocator struct. In the default
+ * implementation this is not used, however this parameter is useful
+ * when the allocator implementation is dealing with a memory pool.
* @param ptr pointer to be freed
*/
- void (*free) (void *ptr);
+ void (*free) (struct axis2_allocator *allocator, void *ptr);
} axis2_allocator_t;
/**
@@ -73,7 +82,7 @@
* @return initialized allocator. NULL on error.
*/
AXIS2_DECLARE(axis2_allocator_t *)
- axis2_allocator_init (axis2_allocator_t * allocator);
+ axis2_allocator_init (axis2_allocator_t *allocator);
/**
* This function should be used to deallocate memory if the default allocator provided by
@@ -84,13 +93,13 @@
axis2_allocator_free(axis2_allocator_t *allocator);
#define AXIS2_MALLOC(allocator, size) \
- ((allocator)->malloc(size))
+ ((allocator)->malloc(allocator, size))
#define AXIS2_REALLOC(allocator, ptr, size) \
- ((allocator)->realloc(ptr, size))
+ ((allocator)->realloc(allocator, ptr, size))
#define AXIS2_FREE(allocator, ptr) \
- ((allocator)->free(ptr))
+ ((allocator)->free(allocator, ptr))
/** @} */
Modified: webservices/axis2/trunk/c/util/src/allocator.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/allocator.c?rev=410611&r1=410610&r2=410611&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/allocator.c (original)
+++ webservices/axis2/trunk/c/util/src/allocator.c Wed May 31 10:43:01 2006
@@ -18,8 +18,15 @@
#include <axis2_utils.h>
#include <stdlib.h>
+void *axis2_allocator_malloc_impl(axis2_allocator_t *allocator, size_t size);
+
+void *axis2_allocator_realloc_impl(axis2_allocator_t *allocator, void *ptr, size_t size);
+
+void axis2_allocator_free_impl(axis2_allocator_t *allocator, void *ptr);
+
+
AXIS2_DECLARE(axis2_allocator_t *)
-axis2_allocator_init (axis2_allocator_t * allocator)
+axis2_allocator_init (axis2_allocator_t *allocator)
{
if (allocator)
return allocator;
@@ -29,9 +36,9 @@
allocator = (axis2_allocator_t *) malloc (sizeof (axis2_allocator_t));
if (allocator)
{
- allocator->malloc = malloc;
- allocator->realloc = realloc;
- allocator->free = free;
+ allocator->malloc = axis2_allocator_malloc_impl;
+ allocator->realloc = axis2_allocator_realloc_impl;
+ allocator->free = axis2_allocator_free_impl;
return allocator;
}
}
@@ -41,11 +48,24 @@
AXIS2_DECLARE(axis2_status_t)
axis2_allocator_free(axis2_allocator_t *allocator)
{
- void (*free_func)(void *) = NULL;
if(allocator)
{
- free_func = allocator->free;
- free_func(allocator);
+ allocator->free(allocator, allocator);
}
return AXIS2_SUCCESS;
+}
+
+void *axis2_allocator_malloc_impl(axis2_allocator_t *allocator, size_t size)
+{
+ return malloc(size);
+}
+
+void *axis2_allocator_realloc_impl(axis2_allocator_t *allocator, void *ptr, size_t size)
+{
+ return realloc(ptr, size);
+}
+
+void axis2_allocator_free_impl(axis2_allocator_t *allocator, void *ptr)
+{
+ return free(ptr);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org