Solved

stl sort

Posted on 2011-09-13
4
337 Views
Last Modified: 2012-05-12
Hi there,

I am interested in finding out the amount of memory that is being used by stl's sort.
I have read the link :http://www.sgi.com/tech/stl/sort.html and there is mention about complexity but nothing about memory .

Could anyone please direct me to the link ?

Thanks,
0
Comment
Question by:zizi21
4 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 167 total points
ID: 36528144
The memory complexity of the std::sort algorithm is not defined in the standard, so there's no way to be sure what the memory complexity is for a given implementation (apart from reading the implementation's documentation).

However, I'd expect the memory complexity to be O(1) or O(log n).

You'll note that the SGI implementation (cfr the link you posted) mentions that the introsort algorithm is used. The introsort algorithm has an O(log n) memory complexity.
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 167 total points
ID: 36528148
Since the standard STL sort is generally a quick sort the worse case memory usage will be O(logn).

http://en.wikipedia.org/wiki/Quicksort
0
 
LVL 6

Assisted Solution

by:theKashyap
theKashyap earned 166 total points
ID: 36538093
As someone mentioned it's implementation dependent.
Find out what's teh implementation (STL code would anyway be available) and then refer to the table in this page, it has the memory complexity described for most common algorithms.

Or did you mean you want a real number, say in KB?
- For that easiest is to run with a profiler (E.g. Rational Quantify)
- Or you can write some code like this or this depending on your needs.
0
 

Author Closing Comment

by:zizi21
ID: 36540708
Thanks for the help..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now