Click here to Skip to main content
15,894,343 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General[Message Deleted] Pin
Member 284578422-Oct-08 8:42
Member 284578422-Oct-08 8:42 
JokeRe: IHTMLServices Pin
Mark Salsbery22-Oct-08 8:47
Mark Salsbery22-Oct-08 8:47 
GeneralRe: IHTMLServices Pin
Member 284578422-Oct-08 9:01
Member 284578422-Oct-08 9:01 
GeneralRe: IHTMLServices Pin
Mark Salsbery22-Oct-08 9:15
Mark Salsbery22-Oct-08 9:15 
GeneralRe: IHTMLServices Pin
led mike22-Oct-08 11:05
led mike22-Oct-08 11:05 
AnswerRe: IHTMLServices Pin
led mike22-Oct-08 8:49
led mike22-Oct-08 8:49 
QuestionCache management implementation for C++ Pin
Ahmed Charfeddine22-Oct-08 6:16
Ahmed Charfeddine22-Oct-08 6:16 
AnswerRe: Cache management implementation for C++ Pin
James R. Twine22-Oct-08 7:57
James R. Twine22-Oct-08 7:57 
   The simplest thing for a simple object cache to do is just allocate objects en masse and manage them in a collection.  For example, if your application deals with a lot of std::string objects, you can allocate up a bunch of them (e.g. 250) at startup, throw them on a std::stack and then pop them off the stack as required.  If you exhaust the stack, allocate another 250 of them and put them on the stack.

   When done with an object, "free" it by putting it back on the stack so that something else can use it.

   In an active, stable system, the buffers of the string objects will stabilize over time by growing to a general size and then staying there, and multiple threads will be able to take advantage of locality with the objects.

   This results in less overall allocations and existing allocations, both for the strings and their buffers, due to reuse instead of destruction and re-creation/re-allocation.

   In applications that abuse string objects, you can see a decent performance improvement at the expense greater memory usage.  (Although as I said, the memory usage stablizes over time.)

   This approach also works well in threadpool situations where you have multiple worker threads waiting on an IOCPs -- the "context object" that is thrown to the pool of worker threads can come from a collection of reused objects which minimizes the overhead of context management.  Same thing with data buffers, etc.

   Performance can be further improved by allocating larger blocks of memory and then instantiating objects in that block of memory -- see placement new for more information.  This further reduces the memory management your application needs to make, and "memory management" == time.

   Peace!

-=- James
Please rate this message - let me know if I helped or not!<hr></hr>If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles



GeneralRe: Cache management implementation for C++ Pin
Ahmed Charfeddine23-Oct-08 23:17
Ahmed Charfeddine23-Oct-08 23:17 
Questionhow to set journal hook? Pin
anminxin22-Oct-08 5:21
anminxin22-Oct-08 5:21 
AnswerRe: how to set journal hook? Pin
Rajesh R Subramanian22-Oct-08 20:07
professionalRajesh R Subramanian22-Oct-08 20:07 
Questionsimple interpreter Pin
harcaype22-Oct-08 4:56
harcaype22-Oct-08 4:56 
AnswerRe: simple interpreter Pin
Mark Salsbery22-Oct-08 5:26
Mark Salsbery22-Oct-08 5:26 
GeneralRe: simple interpreter Pin
CPallini22-Oct-08 9:26
mveCPallini22-Oct-08 9:26 
AnswerRe: simple interpreter Pin
CPallini22-Oct-08 9:30
mveCPallini22-Oct-08 9:30 
AnswerRe: simple interpreter Pin
David Crow22-Oct-08 10:02
David Crow22-Oct-08 10:02 
GeneralRe: simple interpreter Pin
harcaype23-Oct-08 2:10
harcaype23-Oct-08 2:10 
QuestionRe: simple interpreter [modified] Pin
David Crow23-Oct-08 2:54
David Crow23-Oct-08 2:54 
AnswerRe: simple interpreter Pin
harcaype23-Oct-08 4:23
harcaype23-Oct-08 4:23 
QuestionControl outgoing TCP/IP connections Pin
od@ananzi.co.za22-Oct-08 4:23
od@ananzi.co.za22-Oct-08 4:23 
AnswerRe: Control outgoing TCP/IP connections Pin
Richard Andrew x6422-Oct-08 18:00
professionalRichard Andrew x6422-Oct-08 18:00 
Questioncovert / cast int to char* with a twist Pin
Programm3r22-Oct-08 4:22
Programm3r22-Oct-08 4:22 
AnswerRe: covert / cast int to char* with a twist Pin
James R. Twine22-Oct-08 5:08
James R. Twine22-Oct-08 5:08 
AnswerRe: covert / cast int to char* with a twist Pin
Mark Salsbery22-Oct-08 5:12
Mark Salsbery22-Oct-08 5:12 
QuestionHo wto close running application before uninstallation?? Pin
tarunclassic22-Oct-08 3:46
tarunclassic22-Oct-08 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.