SFML community forums

Help => Audio => Topic started by: HeinzK on May 10, 2012, 01:37:41 pm

Title: Memory released ..
Post by: HeinzK on May 10, 2012, 01:37:41 pm
deleted
Title: Re: Memory released ..
Post by: Laurent on May 10, 2012, 01:46:51 pm
Sorry but I don't understand your question :-\

And do you really need all these dynamic allocations?
Title: Re: Memory released ..
Post by: HeinzK on May 10, 2012, 01:52:57 pm
Yes, I need it for a std::vector<> array.
My questino: is it a memoryleak possible, when I do that?
Title: Re: Memory released ..
Post by: Laurent on May 10, 2012, 01:55:13 pm
Quote
Yes, I need it for a std::vector<> array.
std::vector already knows how to dynamically grow when you add elements, the elements themselves don't need to be dynamically allocated.

Quote
My questino: is it a memoryleak possible, when I do that?
Yes, everything that is allocated with new must be destroyed with delete. SFML never takes the ownership of user objects.
Title: Re: Memory released ..
Post by: Zefz on May 11, 2012, 12:15:54 pm
std::vector does not need to hold pointers.

std::vector<SoundBuffer> myVector;

//Load some sounds
myVector.resize(3);
myVector[0].loadFromFile("sound1.wav");
myVector[1].loadFromFile("sound2.wav");
myVector[2].loadFromFile("sound3.wav");

myVector.clear();  //all memory is freed! no memory leaks
 
Title: Re: Memory released ..
Post by: HeinzK on May 15, 2012, 11:12:12 am
OK, but I have different ranges.
At this moment all things are working by me.
Thank you for the tip.