2010-08-08 15:20:24 +04:00
/* -------------------------------------------------------------------------- */
2015-09-23 16:03:22 +03:00
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
2010-08-08 15:20:24 +04:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef MEM_COLLECTOR_H_
# define MEM_COLLECTOR_H_
2010-08-10 18:30:54 +04:00
# define MEM_COLLECTOR_CHUNK 100
2010-08-08 15:20:24 +04:00
/**
* mem_collector . A simple struct to track strdup ' ed strings in lex parsers .
* It prevents memory leaks in case of parse errors
*/
typedef struct mem_collector_
{
char * * str_buffer ;
int size ;
2010-08-10 18:30:54 +04:00
int next ;
2010-08-08 15:20:24 +04:00
} mem_collector ;
/**
* Initialize mem_collector internal memory buffers . MUST be called before
* using any relared function
* @ param mc pointer to the mem_collector
*/
void mem_collector_init ( mem_collector * mc ) ;
/**
* Frees mem_collector internal resources .
* @ param mc pointer to the mem_collector
*/
void mem_collector_cleanup ( mem_collector * mc ) ;
/**
* Strdup ' s a string
* @ param mc pointer to the mem_collector
* @ param str string to be copied
* @ return pointer to the new string
*/
char * mem_collector_strdup ( mem_collector * mc , const char * str ) ;
2010-09-02 22:44:14 +04:00
# endif /*MEM_COLLECTOR_H_*/