tiny clean up of memory allocation

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26887 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2010-06-17 13:54:09 +00:00
parent 8d3dbb8809
commit 95b0cefad0
4 changed files with 23 additions and 10 deletions

View file

@ -56,3 +56,16 @@ void* skin_buffer_alloc(size_t size)
#endif
return retval;
}
#ifdef ROCKBOX
/* get the number of bytes currently being used */
size_t skin_buffer_usage(void)
{
return buffer_front - buffer;
}
size_t skin_buffer_freespace(void)
{
return SKIN_BUFFER_SIZE - skin_buffer_usage();
}
#endif

View file

@ -28,4 +28,8 @@
void skin_buffer_init(size_t size);
/* Allocate size bytes from the buffer */
void* skin_buffer_alloc(size_t size);
/* get the number of bytes currently being used */
size_t skin_buffer_usage(void);
size_t skin_buffer_freespace(void);
#endif

View file

@ -51,6 +51,8 @@ static int skin_parse_conditional(struct skin_element* element,
static int skin_parse_comment(struct skin_element* element, char** document);
static struct skin_element* skin_parse_code_as_arg(char** document);
struct skin_element* skin_parse(const char* document)
{
@ -836,15 +838,10 @@ static struct skin_element* skin_parse_code_as_arg(char** document)
/* Memory management */
char* skin_alloc(size_t size)
{
return skin_buffer_alloc(size);
}
struct skin_element* skin_alloc_element()
{
struct skin_element* retval = (struct skin_element*)
skin_alloc(sizeof(struct skin_element));
skin_buffer_alloc(sizeof(struct skin_element));
retval->type = UNKNOWN;
retval->next = NULL;
retval->tag = NULL;
@ -858,19 +855,19 @@ struct skin_element* skin_alloc_element()
struct skin_tag_parameter* skin_alloc_params(int count)
{
size_t size = sizeof(struct skin_tag_parameter) * count;
return (struct skin_tag_parameter*)skin_alloc(size);
return (struct skin_tag_parameter*)skin_buffer_alloc(size);
}
char* skin_alloc_string(int length)
{
return (char*)skin_alloc(sizeof(char) * (length + 1));
return (char*)skin_buffer_alloc(sizeof(char) * (length + 1));
}
struct skin_element** skin_alloc_children(int count)
{
return (struct skin_element**)
skin_alloc(sizeof(struct skin_element*) * count);
skin_buffer_alloc(sizeof(struct skin_element*) * count);
}
void skin_free_tree(struct skin_element* root)

View file

@ -122,7 +122,6 @@ struct skin_element
struct skin_element* skin_parse(const char* document);
/* Memory management functions */
char *skin_alloc(size_t size);
struct skin_element* skin_alloc_element(void);
struct skin_element** skin_alloc_children(int count);
struct skin_tag_parameter* skin_alloc_params(int count);