|
If you are dynamically allocating elements, you shouldn't have to clear them (as Dan Bale - not Dale states). There are generally 2 ways to deal with this. The first way is to keep a counter with the actual number of active elements. So if you are only using 8 out of this 1000 elements, you would only iterate (for loop) through those 8, never even looking at the other 9992 records so you don't' care what they contain. Another way is to load an all 9's type value into the element past the one you are actively using so you know it's the end, an EOF (EOE?) marker if you will. If you have a text field in the structure, I would load something like '*** END ***'. The counter method is the preferred method, I believe, as all 9's can sometimes be valid data. Dynamic memory allocation can get pretty tricky and there are a lot of maintenance issues in your program you are going to have to deal with so you don't get weird errors and buffer overflows. If you can do what you want without dynamic memory allocation you should use some other method (as Hans stated). Issues you want to be sure to look at: 1. Make sure you don't try to allocate a 1001's element in a 1000 dimed array. 2. Make sure that elements you are looking at have been allocated. 3. Make sure that elements you are looking at have been initialized. 4. Make sure that you deallocate elements when you are done with them. 5. Make sure you have some method to detect an out of memory type error. HTH, Regards, Jim Langston -----Original Message----- From: Smith, Nelson [mailto:NSmith@lincare.com] So what is the best way to clear previously used occurrances? Do I have to loop through all of them clearing them one at at time? Further debugging did prove that after using 8 occurs, then resetting the MODS to use 1 byte, then starting over and reallocating one occurrance's worth of memory at a time, on the fifth occurrance, I began picking up previously loaded data. So, apparently, REALLOC does not clear the new memory it is allocating. At least not if it has been used previously in the same job?
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.