c++ - Using boost.pool instead of 'new' for container of objects -


I am working in that code base, currently this is the code that often does this: < Pre> // In the header: class labels {public: zero parascript (); Private: Letter * M_AramAire; }; // in CPP: Passive Parsext () {Delete} M_IERRE; M_myArray = new letter [string_length]; Basically every time the string changes into a label, we delete the old letters and delete them again. These letter objects are somewhat lightweight, but this is often the case since I std :: vector & lt; Letter & gt; because each push_back () will be the result of a copy I also want to avoid copying.

Should use Bulb Pool Support here? I can imagine doing this (this is a pseudocode, because I'm not sure how to use the pool yet):

  // In the header: class Label {public : void ParseText (); Private: std :: vector & lt; Letter *> M_myArray; Promotion :: object_pool m_pool; }; // CPP: parseText () {// loop through each element in the loop m_myArray and call pool :: free m_myArray.clear (); // Loop each letter and create a new letter object in the container (...) {m_myArray.push_back (m_pool.malloc ()); // Constructor is not sure how to control params / / ......}   

To avoid this copy and avoid avoiding allocation, however, I code Maintenance has been reduced because there is too much boilerplate involved in adding / removing objects from the vector.

I have thought of using the boost with custom deliliter: filter_wector, but not sure if this helps a lot, it helps in cleaning, but I still want to pool: : Malloc () has to call while push_backing.

Use custom allocation with std :: vector to understand either because it is already fixed and will not shrink in size.

Can anyone understand the "best" solution for this problem?

I think what I do is, vector to reduce the amount of allocation Use and resize , and Allow letters to be reused, we have something like this:

  // In the header: Class Label {public: void ParseText (); Private: std :: vector & lt; Letter & gt; M_myArray; }; // in CPP: Zero Parsext () {m_myArray.resize (string_length); // [...]   

With such an approach in this way, the number of letter items as much as possible is being reused from the previous example < />

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -