Skip to Content.
Sympa Menu

patterns-discussion - RE: [patterns-discussion] Using Design Patterns without dynamic memoryallocation

patterns-discussion AT lists.siebelschool.illinois.edu

Subject: General talk about software patterns

List archive

RE: [patterns-discussion] Using Design Patterns without dynamic memoryallocation


Chronological Thread 
  • From: Jesús Alonso <kenchoweb AT hotmail.com>
  • To: ralph_malph AT yahoo.com, patterns-discussion AT cs.uiuc.edu
  • Cc:
  • Subject: RE: [patterns-discussion] Using Design Patterns without dynamic memoryallocation
  • Date: Tue, 29 Mar 2005 17:14:18 +0200
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

As far as I can remember right now, the only patterns that actually require dynamic memory allocation are the first ones (talking about GoF -- there are dozens of patterns out of that book too): The creational patterns.

Think that many patterns just do some encapsulation or enhance the structure of the overall design. For instance, the facade pattern I mentioned earlier, just encapsulates complex procedures in a simple class, providing a clean interface for the most common operations (if you just use some basic queries or operations on a database, and always with the same structure, you don't need the application to mess with all the database access methods, so you create a facade with methods like addRegister(), getRegisters()... cleaning the design by encapsulating all the database access specifics in one class).

About the Object Pool pattern, it's quite helpful for the case of a fixed budget for creation (I guess it's your problem). It helps working with declarations like "ObjectType array[FIXED_AMOUNT];", where you define the memory allocation in compile-time rather than run-time. Of course, there are still obvious issues because you can't have more objects than FIXED_AMOUNT, but that problem will be present everytime you can't allocate memory dynamically.

So don't give up: Designe patterns have been the best discovery of my life :D They'll help you a lot for sure ;)

Regards,
Kencho

Hi Kencho,

Thanks for your reply. I am still learning the
patterns, so I'll take a close look at the patterns
you mentioned.

The problem is not that we have limited memory, but
that we are not allowed to use dynamically allocated
memory (no heap). I have envisioned the use of
statically created objects in the place of dynamically
created ones, and I just wanted to make sure that it
made sense to do it that way in light of how the
patterns are implemented. It seems like I see a lot
of dynamic memory being allocated in the examples of
the books I have read (GoF, Head First DP), but I now
know that it is not usually a requirement but rather a
convenience or merely the "standard". There doesn't
seem to be much consideration for real-time systems in
the books I read, and most of them use Java, which is
right out for me.

Thanks again,

Andre
--- Kencho san
<kenchoweb AT hotmail.com>
wrote:
> I'm not sure what's your problem, but I'll try to
> answer.
>
> Almost any non-creational pattern can be aplied
> without dynamic memory
> allocation, for instance the template method, state
> pattern, facade,
> adapter... all of them can make use of
> composition-like relationships rather
> than reference relationships (note that reference
> doesn't mean dynamic
> memory allocation, but usually involves it)
>
> If your problem is about design patterns helping you
> avoid dynamic memory
> allocation (you have space for a maximum amount of
> objects and can't waste
> time or memory to store more...), I would suggest
> taking a look to the
> Object Pool pattern, which is a very clever way to
> reuse already existing
> objects instead of creating and destroying them
> constantly
>
> Hope that helps
>
> >Hello all, looking at archives I'm not sure how
> >"alive" this list is, but someone out there might
> be
> >listening.
> >
> >I'm interested in people's opinions as to whether
> >design patterns would be useful if you could not
> >dynamically allocate memory.
> >
> >I am new to patterns and find them quite
> interesting.
> >I am considering putting in some effort to
> comprehend
> >them, but my projects at work include embedded
> >safety-critical real-time systems, and one of the
> >things that we do not use is dynamic memory
> >allocation.
> >
> >If anyone has an opinion as to whether I should
> delve
> >into patterns for this type of software (i.e. you
> have
> >considered doing them and/or done them in similar
> >systems before) I'd be interested to hear it.
> >
> >Thanks!
> >
> >
> >
> >__________________________________
> >Do you Yahoo!?
> >Yahoo! Small Business - Try our new resources site!
> >http://smallbusiness.yahoo.com/resources/
> >
> >_______________________________________________
> >patterns-discussion mailing list
>
>patterns-discussion AT cs.uiuc.edu
>
>http://mail.cs.uiuc.edu/mailman/listinfo/patterns-discussion
>
>
>



__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250






Archive powered by MHonArc 2.6.16.

Top of Page