[Dev-C++] Question about software design
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <and...@su...> - 2007-11-20 17:28:09
|
Dear users, a) I have a project file, with some .c and .h files; b) the main() function is worried in only find one answer, which is the best distance (an integer) and the best tour, an 1-D vector; c)to find this answer, I have to manipulate a lot of 1-D and 2-D vectors, and other simple variables in specific functions. I´m using parameter passing functions; d) the size of these vectors is variable and it depends of the user settings. So, I have to use dynamic allocation with pointers; e) I´m using two functions: AllocateResources() in the beginning of the execution and FreeResources() at the end to do all the allocations needed to run my functions. These functions are in the main() scope. Because of this, all the vectors need to be declared in the main(). My problem is: Many of these vectors are only related to specific functions, that is, they are only used in some functions and I have to make reference to them in the main() scope. If I put the allocation inside the functions, I will make thousands of malloc´s and free´s for the same thing! My question is: Is there any clever way to do this (make only one allocation, run the program, free the resources at the end of the execution and DON´T NEED TO EXIBIT ALL THESE RESOURCES-the vectors IN THE main() SCOPE)? Regards Andre No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.16.1/1140 - Release Date: 19/11/2007 19:05 |