Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.![]() ![]() |
Apr 18 2008, 06:38 PM
Post
#1
|
|
|
Big Brother is Watching You ![]() ![]() ![]() ![]() ![]() ![]() Group: HJT Senior Classmen Posts: 1,713 Joined: 17-January 08 From: Airstrip One Member No.: 184,215 |
CODE std::string getTextOfCommand(char command[]){ //adds "> tempfile.txt" to the command string, executes it with system() //reads the file to a string, deletes the file, and deletes the file. std::string retVar; char *holder; long unsigned int length; holder = new char[strlen(command)+16]; strcpy(holder,command); strcat(holder," > tempfile.txt"); system(holder); delete [] holder; std::ifstream file("tempfile.txt",std::ios::in); file.seekg(0,std::ios_base::end); length = file.tellg(); holder = new char[length]; file.seekg(0,std::ios_base::beg); file.read(holder,length); file.close(); retVar=holder; delete [] holder; system("del /f tempfile.txt"); return retVar; } I have it returning a string so that I can delete the character array "holder" before the program exits. However, I am curious: this program is designed to run for maybe 30 seconds max, and this function called maybe 3 or 4 times. If I allocate something with the new operator, and the program exits, does the Operating System keep the ram marked as used? Or is any ram used by a program released by the program upon exit? Billy3 EDIT: The wikipedia article here seems to say I dont have to worry about deleting the array if I plan to have it destroyed at exit anyway: http://en.wikipedia.org/wiki/Memory_leak QUOTE The memory leak would only last as long as the program was running. For example: if the lift's power were turned off the program would stop running. When power was turned on again, the program would restart and all the memory would be available again, and the slow process of leaking would start again. Can anyone verify this? This post has been edited by Billy O'Neal: Apr 18 2008, 07:06 PM -------------------- In the event I fail to reply within twenty-four hours, feel free to send me a PM.
Have I helped you? If so, please sign My Guestboox to help me get into college! Join BC.com's Folding Team (#38444)! Help Stanford University find a cure for diseases! ![]() |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 5th July 2008 - 04:52 PM |