Hadley Mendelsohn is the co-host and executive producer of the podcast Dark House. When she's not busy writing about interiors, you can find her scouring vintage stores, reading, researching ghost stories, or stumbling about because she probably lost her glasses again. Along with interior design, she writes about everything from travel to entertainment, beauty, social issues, relationships, fashion, food, and on very special occasions, witches, ghosts, and other Halloween haunts. Her work has also been published in MyDomaine, Who What Wear, Man Repeller, Matches Fashion, Byrdie, and more.
Design Pool worked closely with design firm ChangeUp to create a unique optical pattern for upholstery at Six Point Brewery in Brooklyn, NY. This pattern was printed on EnviroLeather Prints by LDI Interiors and is being used on seating.
I have a program that contains a processing phase that needs to use a bunch of different object instances (all allocated on the heap) from a tree of polymorphic types, all eventually derived from a common base class.
As the instances may cyclically reference each other, and do not have a clear owner, I want allocated them with new, handle them with raw pointers, and leave them in memory for the phase (even if they become unreferenced), and then after the phase of the program that uses these instances, I want to delete them all at once.
Specifically I am concerned about the fact that the this pointer is used to construct a std::unique_ptr in the base class constructor, before the derived class constructor has completed. Does this result in undefined behaviour? If so is there a workaround?
Pool allocation is a memory allocation scheme that is very fast, but limited in its usage. For more information on pool allocation (also called simple segregated storage, see concepts concepts and Simple Segregated Storage.
Using Pools gives you more control over how memory is used in your program. For example, you could have a situation where you want to allocate a bunch of small objects at one point, and then reach a point in your program where none of them are needed any more. Using pool interfaces, you can choose to run their destructors or just drop them off into oblivion; the pool interface will guarantee that there are no system memory leaks.
fast_pool_allocator is also a general-purpose solution but is geared towards efficiently servicing requests for one chunk at a time; it will work for contiguous chunks, but not as well as pool_allocator.
Memory management is tricky business (threading, caching, alignment, fragmentation, etc. etc.) For serious production code, well-designed and carefully optimized libraries are the way to go, unless your profiler demonstrates a bottleneck.
The first problem that I can think of is thread safety. For example, what happens when objects of the same base are created from different threads? A solution might be to protect the pool access with mutually exclusive locks. Though I think a better way to do this is to make that pool a thread-specific object.
The second problem is invoking an undefined behavior in case where derived class's constructor throws an exception. You see, if that happens, the derived object won't be constructed, but your B's constructor would have already pushed a pointer to this to the vector. Later on, when the vector is cleared, it would try to call a destructor through a virtual table of the object that either doesn't exist or is in fact a different object (because new could reuse that address).
Hmm, I needed almost exactly the same thing recently (memory pool for one phase of a program that gets cleared all at once), except that I had the additional design constraint that all my objects would be fairly small.
To answer your question, you're not invoking undefined behaviour since nobody is using the pointer until the object is fully constructed (the pointer value itself is safe to copy around until then). However, it's a rather intrusive method, as the object(s) themselves need to know about the memory pool. Additionally, if you're constructing a large number of small objects, it would likely be faster to use an actual pool of memory (like my pool does) instead of calling out to new for every object.
If the derived constructor fails, you are left with an issue later when you are likely to have a dangling pointer at least sitting in the vector, as that address space it [the derived class] thought it was getting would be freed to the operating environment on failure, but the vector still has the address as being of the base class type.
Note that a vector, although kind of useful, is not the best structure for this, and even if it was, there should be some inversion of control involved here to allow the vector object to control initialisation of your objects, so that you have awareness of success/failure.
Answer: Not really, for the reasons mentioned above, plus others (Pushing a vector past it's end point basically ends up with a malloc which is unnecessary and will impact performance.) Ideally you want to use a pooling library, or a template class, and even better, separate the allocation/de-allocation policy implementation away from the pool implementation, with a low level solution already being hinted at, which is to allocate adequate pool memory from pool initialisation, and then use this using pointers to void from within the pool address space (See Alex Zywicki's solution above.) Using this pattern, the pool destruction is safe as the pool which will be contiguous memory can be destroyed en masse without any dangling issues, or memory leaks through losing all references to an object (losing all reference to an object whose address is allocated through the pool by the storage manager leaves you with dirty chunk/s, but will not cause a memory leak as it is managed by the pool implementation.
Answer: This is a localised design decision based on what you are comfortable with, but to be honest, your implementation (no controlling structure/aggregate, possibly cyclic sharing of sub sets of objects) suggests to me that you would be better off with a basic linked list of wrapper objects, each of which contains a pointer to your superclass, used only for addressing purposes. Your cyclical structures are built on top of this, and you simply amend/grow shrink the list as required to accommodate all of your first class objects as required, and when finished, you can then easily destroy them in effectively an O(1) operation from within the linked list.
Having said that, I would personally recommend that at this time (when you have a scenario where pooling does have a use and so you are in the right mind-set) to carry out the building of a storage management/pooling set of classes that are paramaterised/typeless now as it will hold you in good stead for the future.
don't worry about what i'm inheriting from. i have been using this allocator in conjunction with a memory pool. but basically instead of getting the memory from operator new i am getting memory from a memory pool. the internal workings are the same essentially.
This code is fully functional except for a few lines which will need to be changed because of my inheritance and use of the memory pool. but I bet you can figure out what needs to change and just let me know if you need a hand changing the code. This code has not been tested in any sort of professional manor and is not guaranteed to be thread safe or anything fancy like that. i just whipped it up and thought i could share it with you since you seemed to need help.
To start the design process, we first needed to decide on a location. Honestly this took us the longest to figure out, as most of our land was either hilly landscape or cactus garden. We ruled these areas out in our minds initially, but realized that a hill could become a part of the design rather than deter it. We ended up building the pool into the hill right outside of our sliding glass doors to our living room, making the swimming pool design both easily accessible and giving it the look of an infinity pool.
When it came time to design our pool (we designed it ourselves), we allowed the hill that we were building into to dictate the size and structure of the pool design. You can see in the drawings that we did below that the lower half of the hill is above ground, while the upper half of the hill is flush with the ground. This gave us the opportunity to create a patio around the pool on the one side, and a short plaster wall on the other side to garden around.
For a natural to fit in with the surrounding landscape, we chose a colonial cream flagstone with alabaster grout for the decking. We love the organic lines that the flagstone offers to the round pool, encouraging the feel of a natural body of water. When using flagstone around a pool, make sure to use a water based penetrating sealer to seal the stone and to protect it from potential water damage.
Thank you! Our pool contractor handled the permitting, but the county just moved to an online process and it seemed to move pretty fast. It was more about scheduling the inspector that seemed to take the longest.
www.SlideRuleEra.net RE: Swimming Pool Design Loui1 (Structural)(OP)26 Jul 06 07:51Thank you for the link reference, but that thread, from over 2 years ago, does not include any useful structural design references. It's got some links to references that show you how to design the dimensions of the pool...but not anything for the structure.
I've already searched engtips. RE: Swimming Pool Design Ussuri (Civil/Environmental)26 Jul 06 08:02Surely the structural design is the same as for any tank??? RE: Swimming Pool Design JAE (Structural)26 Jul 06 09:40Loui1 - we do a number of pools in our firm and we went through a research effort to determine what there might be "out there" as far as standards, design criteria, etc. for structural design of pools. Not much found.
We simply use our engineering reasoning/design skills and design the pool walls as cantilever retaining walls resisting two load conditions:
1. Pool full with water pressure on one side and earth pressure on the other (based on geotech report).
2. Pool empty (for maintenance or over the winter) with earth pressure on one side only.
Load combination 2 most always controls. We morph the footing of the wall into the floor of the tank. Joint details are critical - we use waterstops at all tank joints. That's the overall concept in a nutshell. There's detail and durability issues for the concrete of course. And the geometric design criteria you referred to in the link is also critical. We usually have to submit the pool design to an agency in our state that reviews it for health considerations.
RE: Swimming Pool Design southard2 (Structural)26 Jul 06 11:35You might want to stipulate that the earth is to be cut back until the walls are cured. Than added water and earch backfill to the pool 1 ft increments. While the design should always include the load case with the pool empty it is a good construction practice to eliminate problems.
One problem that I've had trouble finding help on is bouyancy. I've heard the fiberglass pools have sometimes popped out of the ground like boats floating on water. The construction practice above ensures that this boat effect doesn't happen during construction RE: Swimming Pool Design mrengineer (Structural)26 Jul 06 15:17With regard to JAE load case (1), I believe it is common practice in sanitary structures to ignore the resistance provided by the soil on the outside of the structure. RE: Swimming Pool Design JAE (Structural)26 Jul 06 15:39That's a good idea mrengineer.
RE: Swimming Pool Design Loui1 (Structural)(OP)26 Jul 06 19:42Thanks for the replies. So it appears I'm not going to be "swimming" in a "pool" of specific references or design guides.
The design cases you've listed are all things already in my mind. I've heard of concrete pools floating out of the ground due to bouyancy....not even from groundwater, just a leaky pool floated on up when emptied. RE: Swimming Pool Design soflapoolboy (Materials)27 Dec 06 21:54Check out the south florida building code. Available via construction school book stores. It is very detailed about the do's and don't of pool design keeping safety in mind along with some of the toughest building codes in the USA- Thanks to hurricane Andrew that hit us in the early 90's.
Pools "pop out" of the ground for two reasons.
1. Pools get drained in areas with high water tables without removing the hydrostatic plug located in the pool's main drain. Turning the pool basically into a concrete boat.
This is usually done either by idiots working for pool companies or homeowners that are just unaware. 99% of pools have a wellpoint buried 2 feet below the main drain in the pool. This wellpoint can be hooked up to a dewatering pump that will actually dewater the earth and cease any uplift pressure.
2. Pools in areas with expansive soil conditions when subject to high rainfall amounts. Basically squeezing the pool until it pops. This is not very common due to the weight of the water and concrete- also the friction of the soil on the outside of the pool walls tends to hold them down.
You can contact www.Hornerexpress.com for your engineering plans. googletag.cmd.push(function() googletag.display('div-gpt-ad-1406030293255-2'); ); Red Flag This PostPlease let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.
CancelRed Flag SubmittedThank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.