Monday 15 September 2014

c - Extract pointer to data from GPtrArray -


I use the GPtrArray structure to capture the dynamically allocated section of the pointer I am here. As I have to empty the memory as simple and as right as possible, I set the callback g_ptr_array_new_with_free_func () which will free an element of the indicator array. Thus, when i g_ptr_array_free () Calling for all the elements of the array, it is called callback which is filling the memory allocated correctly. Here are some pseudo codes that describe the problem:

  ... GPtrArray * stack = g_ptr_array_new_with_free_func (pt_free_stack_element); If (...) {... g_ptr_array_free (stack); ...} If (interrupt) {// Here I need to do something like a pop for the stack / / I want to get the pointer on some allocated element, // and want to remove it from the stack, but // storage of this element without memory}   

The problem is that the documentation says that any g_ptr_array_remove () , g_ptr_array_remove_index () , g_ptr_array_remove_fast () , g_ptr_array_remove_index_fast () by destroying the element's memory by calling callback if it is set. As you see I have set up the callback.

Well, how can I do this? How do I remove any mention from the array of this indicator, but without the release of the element's memory can I get an element like g_ptr_array_index () ?

you can do this:

  g_ptr_array_set_free_func (stack, blank ); P = g_ptr_array_index (Stack, I); G_ptr_array_remove_index (Stack, I); G_ptr_array_set_free_func (stack, pt_free_stack_element);    

No comments:

Post a Comment