Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Basic questions about u++
Re: Basic questions about u++ [message #23296 is a reply to message #23294] Wed, 07 October 2009 18:14 Go to previous messageGo to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
irtech wrote on Wed, 07 October 2009 15:18

I'm confused Confused
Mirek said
If the stack frame goes out of scope, object is destryoed via destructor.

Implying it is done automatically.

but mr_ped said
Resources works like in ordinary C++,...If you use some "new", then it's up to you to "delete" of course.


The idea of U++ is to utilize the standard behaviour of C++ to avoid most of the memory management problems that normally plague C++ code. This is done in two main ways:
- Structuring the library so that every object is 'owned' by something. This means declaring objects either on the stack (as local variables) or as member variables. This allows the compiler to clean up by itself when either the owning object is destroyed or the variable goes out of scope.
- Providing the tools (mainly the NTL) necessary to control dynamic memory in a way that fits with the 'everything is owned' style. This means that although new and delete are used internally in the library you rarely, if ever, need them in your application code.

A simple example:
'ordinary' C++ code:
int CalcSomething {
    int *array = new int[256]

    // Do a load of stuff

    delete[] array;
};

U++:
int CalcSomething {
    Buffer<int> array(256); // Buffer is closest to a C array

    // Do a load of stuff
};

By wrapping the new/delete calls in an object (one that has already been thoughly tested) you are able to utilise C++ inbuilt destruction mechanics and avoid the error-prone call to delete. There isn't any 'magic' going on outside of using templates in a clever way

As far as I'm concerned the Upp memory management philosophy is to never use new/delete. There is almost always a better way Smile.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Time to sing praises for MinGW and GCC
Next Topic: online Whiteboard
Goto Forum:
  


Current Time: Mon May 13 00:08:46 CEST 2024

Total time taken to generate the page: 0.01628 seconds