Horde3D

Next-Generation Graphics Engine
It is currently 29.03.2024, 08:28

All times are UTC + 1 hour




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: 06.06.2008, 16:17 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
I just integrated the patch with some slight adjustments. I conserved the pickNode method in Horde3DUtils since I think it's quite convenient. I also changed the clear statement on the internal vector to a resize(0) which may consume more memory but should perform better.
Next to that I also fixed the parallel projection bug in pickNode (respectively pickRay)


Top
 Profile  
Reply with quote  
PostPosted: 06.06.2008, 16:54 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
Great!

Just integrated trunk into my repo here and the errors while zooming into my terrain just vanished :)


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 03:04 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Volker wrote:
I also changed the clear statement on the internal vector to a resize(0) which may consume more memory but should perform better.
Surely you mean the other way round? resize(0) should free all storage, while clear() may only mark it an unused.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 07:59 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
No I thought it it is the way I wrote above. But I'm not sure.

After reading http://www.cplusplus.com/reference/stl/vector/resize.html and http://www.cplusplus.com/reference/stl/vector/clear.html it seems to me that there is no real difference between these calls. I thought I read somewhere that clear would release the allocated memory while resize(0) does not, but a short investigation using google did not certified that.


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 08:48 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
implementation dependent probably...


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 09:42 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
I'm quite sure I read several times in optimization guides that you should use resize instead of clear on vectors. One example:

http://www.gdconf.com/conference/archives/2004/isensee_pete.ppt


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 13:13 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
Linux libstdc++:
clear just calls the equivalent of erase(begin, end). No memory freeing.

resize first checks if the new size is smaller than the old size. If yes (our case), than the equivalent of erase(begin, begin + newSize) is called. No memory freeing.

At least on Linux resize(0) is a bit slower than clear.


Maybe just run the following code on some systems:
Code:
#include <vector>
#include <iostream>

typedef std::vector<int> VI;


int main()
{
        VI vi;

        for(int i = 0; i < 10; ++i)
                vi.push_back(i);

        std::cout << "before clear " << vi.capacity() << " " << vi.size() << "\n";
        vi.clear();
        std::cout << "after clear " << vi.capacity() << " " << vi.size() << "\n";


        VI vi2;
        for(int i = 0; i < 10; ++i)
                vi2.push_back(i);

        std::cout << "before resize(0) " << vi2.capacity() << " " << vi2.size() << "\n";
        vi2.resize(0);
        std::cout << "after resize(0) " << vi2.capacity() << " " << vi2.size() << "\n";


        return 0;
}


Result for libstdc++:
Code:
before clear 16 10
after clear 16 0
before resize(0) 16 10
after resize(0) 16 0


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 13:39 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Codepoet wrote:
Result for libstdc++:
Code:
before clear 16 10
after clear 16 0
before resize(0) 16 10
after resize(0) 16 0

Well, that is a lovely result - no standard way to force a vector to downsize :)

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 14:17 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
There is a standard way - the swap trick ;)

Code:
vector<T>(data).swap(data);


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 16:17 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
Code:
before clear 13 10
after clear 13 0
before resize(0) 13 10
after resize(0) 13 0

vc2005

Codepoet wrote:
There is a standard way - the swap trick ;)

Code:
vector<T>(data).swap(data);

it just swaps, no memory freeing(it also swaps capacities). or you mean it frees memory when temp_vector goes out of scope?


Top
 Profile  
Reply with quote  
PostPosted: 07.06.2008, 19:09 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
kal wrote:
Codepoet wrote:
There is a standard way - the swap trick ;)
Code:
vector<T>(data).swap(data);

it just swaps, no memory freeing(it also swaps capacities). or you mean it frees memory when temp_vector goes out of scope?
Yes, when the temporary vector goes out of scope, it will free its own storage (which was previously the full vector). I had forgotten about this, but it looks like the best way.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group