[Top] [Prev] [Next] [Bottom] [Contents]

SutDestroyList

Deallocates the memory associated with an SutList structure, and calls free on each of its elements.

Synopsis

#include "SutList.h"
int SutDestroyList(pSutList p);

Arguments

p
A pointer to an SutList.

Return Values

Returns -1 if p is NULL, 0 otherwise.

Description

SutDestroyList deallocates the memory associated with a SutList structure, and calls free on each of its elements. The SutList structure and related functions manage a dynamically sized array of void pointers which can be used as a generic container for C/C++ programmers. The list must be deallocated with SutDeleteList() or SutDestroyList(). SutDestroyList deallocates the memory associated with the elements themselves.

Caution is needed in using SutDestroyList to deallocate the elements. If the elements contain pointers to other heap items these will not be deallocated. If the elements are non-heap memory, a disaster will probably occur. Finally, if an item was an element of 2 lists and SutDestroyList was called on both lists, then the element will be free'd twice.

Example

#include "SutList.h"
#include <stdio.h>
pSutList list;
int i, size;
char *str;
char* str1 = "Hello";
char* str2 = "World";
list = SutNewList();
SutAddList(list, strdup(str1));
SutAddList(list, strdup(str2));
size = SutSizList(list);
for (i=0; i<size; i++)
{
	str = (char*) SutGetNList(list, i);
	fprintf(stderr, "%s\n", str);
}
SutDestroyList(list);

See Also



[Top] [Prev] [Next] [Bottom] [Contents]

info@bluestone.com
Copyright © 1997, Bluestone. All rights reserved.