![]() |
|
#1
|
|||
|
|||
File size optimization.CPP / C++ / C Code:
CPP / C++ / C Code:
also i want to ask why i can't call the destructor with only: CPP / C++ / C Code:
CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: file size optimization..What is your question?
I would not make a habit out of calling destructors like that. What exactly are you trying to accomplish? Also, in your destructor, you may want to check to make sure that p is not NULL before freeing it. |
|
#3
|
|||
|
|||
Re: file size optimization..why don't u use constructors and destructors like that?what is wrong with it?i said in the post,it's for saving from file size.three lines means,a place for one more function and i don't want it.also it could be more lines than three.you may be right about freeing p.
|
|
#4
|
|||
|
|||
Re: file size optimization..Why are you worried about 3 lines? That is less than 100 bytes. You should be able to find a hard drive that has millions of bytes (some of them have billions). Saving the file size of your source code should not be a high priority in comparison with writing cleaner code.
|
|
#5
|
|||
|
|||
Re: file size optimization..cleaner code.i was talking about that too.according to you which seems more clear,this one:
CPP / C++ / C Code:
CPP / C++ / C Code:
which is the one that appropriates to less code reuse? if there's another function that does the same function why do i write it again? |
|
#6
|
|||
|
|||
Re: file size optimization..I would probably have done it the opposite way but if that way works for you, more power to you.
The opposite way would be like: CPP / C++ / C Code:
The thing to worry about is if you ever put something in the destructor that you would not want on a regular clear(). I suppose it would work either way. |
|
#7
|
|||
|
|||
Re: file size optimization..but it's unnecessary to make p NULL and size=0 for a stack variable that goes out of scope.so it makes the program run slower.i'm wondering one thing.so if the destructor is this:
CPP / C++ / C Code:
CPP / C++ / C Code:
prints: CPP / C++ / C Code:
in here: s.clear(); tell me this if u know? |
|
#8
|
|||
|
|||
Re: file size optimization..That is correct. If you call the clear() method it will run the destructor, but then it runs the destructor automatically (that's the purpose of the destructor) when it leaves the scope or is deleted.
CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: file size optimization..Quote:
Quote:
I myself kind of missed what was the question in this thread. It was not very clear. Quote:
This thread REALLY confuses me. Could you take some time to state your question clearly if it wasn't already answered. |
|
#10
|
|||
|
|||
Re: file size optimization..fakepoo it's not like you think it's not because of the stack variable that goes out of scope,i stopped the program before return 0; with getchar() and look output,there were two "p deleted" lines.it's because,in the clear function.when i call stack() function,immediately after it jumps to destructor again,before the function finishes.i'm trying to understand this.is there a temporary object there?if there is,which object do the p variable that it makes NULL and the size variable that it makes 0 belongs to?if i declare a variable like u do:
stack<int> s; do they belong to s?or the temporary variable? can we make calls like this in main? s=stack(); if we can do;then should i change the stack(); line in the clear function like this: *this=stack(); |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 19:23 |
| Determing size of a binary file | Dream86 | C++ Forum | 7 | 01-Jun-2005 10:10 |
| Having a problem | Chuckles | Computer Hardware Forum | 19 | 13-Sep-2004 12:17 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The