Click here to Skip to main content
16,007,843 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Code-o-mat20-Dec-08 0:08
Code-o-mat20-Dec-08 0:08 
AnswerRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Stuart Dootson20-Dec-08 1:21
professionalStuart Dootson20-Dec-08 1:21 
GeneralRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Shameer E.A.20-Dec-08 18:39
Shameer E.A.20-Dec-08 18:39 
GeneralRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Randor 20-Dec-08 18:54
professional Randor 20-Dec-08 18:54 
GeneralRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Shameer E.A.20-Dec-08 19:17
Shameer E.A.20-Dec-08 19:17 
AnswerRe: Problem sending data from TCP/IP server (used CAsyncSocket::Send) Pin
Randor 20-Dec-08 7:46
professional Randor 20-Dec-08 7:46 
QuestionLooking for an ADT that can sort by view (so to speak) [modified] Pin
Mustafa Ismail Mustafa19-Dec-08 20:35
Mustafa Ismail Mustafa19-Dec-08 20:35 
AnswerRe: Looking for an ADT that can sort by view (so to speak) Pin
Stuart Dootson20-Dec-08 1:00
professionalStuart Dootson20-Dec-08 1:00 
[edit]Well, that was good timing - between the time I started and posted this, you added your update about Boost.MultiIndex - DOH![/edit]

Something like Boost.MultiIndexwould fit the bill. I've used it, it allows you to index a collection of objects in multiple ways. It can be a bit difficult to work out how to get started with it (extreme template madness!), but it is very easy to use after that. Just make sure you're NOT trying to use it with VC6 - that's a sure path to insanity.

The other way is to do it yourself (this I have also done!). The easiest way is to emulate what Boost.MultiIndex does. Hold the index in some collection, then present multiple indices of that collection. I managed the objects using Boost shared_ptrs, like so:

class SomeObject { class-implementation };
class MultiIndexCollection
{
  typedef boost::shared_ptr<SomeObject> SomeObjectPtr;
  typdef std::vector<SomeObjectPtr> SomeObjects;

  void AddObject(SomeObject const& o) { someObjects_.push_back(SomeObjectPtr(new SomeObject(o))); }

  SomeObjects const& GetIndex1() const { return index1_; }
  . . . . . 
  SomeObjects const& GetIndex1() const { return indexn_; }

  void ReIndex() { reconstruct the indices by sorting them };

private:
  SomeObjects someObjects_;
  SomeObjects index1_;
  . . . . . 
  SomeObjects indexn_;
};


I was lucky enough that the app could be split into two phases - object insertion and object lookup, so I could handle re-indexing at a point in the app's lifetime. If you can't do this, things are a bit trickier. You could do something like have a 'dirty index' flag, which you set true when AddObject is called. Index retrieval would then trigger a re-index if this 'dirty index' flag is set true. The problem with this is that the performance spikes implied by re-indexing aren't as visible or predictable, as they're hidden inside the index getters.

The re-indexing sorts the object pointers based on some criteria. After indexing, you can use the indices with a binary search, as they've been sorted.

BTW - using sorted vectors as indices like this has, I believe, been shown to be more efficient than (say) std::maps for this use case.

After seeing this, you may well just plump for the Boost.MultiIndex approach...I probably would now, I suspect - it's just that I wrote the above app with VC6, so most Boostyness was out of bounds. And by the time I upgraded to VC7.1, the app was mature enough that I wasn't going to bother going back and changing it - it ain't broke, I'm not fixing it!
GeneralRe: Looking for an ADT that can sort by view (so to speak) Pin
Mustafa Ismail Mustafa20-Dec-08 1:21
Mustafa Ismail Mustafa20-Dec-08 1:21 
QuestionHow can change CRect Value? Pin
Le@rner19-Dec-08 20:30
Le@rner19-Dec-08 20:30 
AnswerRe: How can change CRect Value? Pin
Hamid_RT19-Dec-08 20:45
Hamid_RT19-Dec-08 20:45 
GeneralRe: How can change CRect Value? Pin
Le@rner19-Dec-08 21:04
Le@rner19-Dec-08 21:04 
GeneralRe: How can change CRect Value? Pin
Code-o-mat19-Dec-08 21:55
Code-o-mat19-Dec-08 21:55 
GeneralRe: How can change CRect Value? Pin
Le@rner19-Dec-08 23:21
Le@rner19-Dec-08 23:21 
GeneralRe: How can change CRect Value? Pin
Code-o-mat19-Dec-08 23:26
Code-o-mat19-Dec-08 23:26 
GeneralRe: How can change CRect Value? Pin
Le@rner20-Dec-08 0:22
Le@rner20-Dec-08 0:22 
GeneralRe: How can change CRect Value? Pin
Code-o-mat20-Dec-08 0:28
Code-o-mat20-Dec-08 0:28 
GeneralRe: How can change CRect Value? Pin
Le@rner20-Dec-08 1:54
Le@rner20-Dec-08 1:54 
GeneralRe: How can change CRect Value? Pin
Code-o-mat20-Dec-08 2:19
Code-o-mat20-Dec-08 2:19 
GeneralRe: How can change CRect Value? Pin
Le@rner21-Dec-08 17:29
Le@rner21-Dec-08 17:29 
GeneralRe: How can change CRect Value? Pin
Code-o-mat21-Dec-08 22:05
Code-o-mat21-Dec-08 22:05 
GeneralRe: How can change CRect Value? Pin
Le@rner21-Dec-08 20:41
Le@rner21-Dec-08 20:41 
GeneralRe: How can change CRect Value? Pin
Code-o-mat21-Dec-08 22:02
Code-o-mat21-Dec-08 22:02 
GeneralRe: How can change CRect Value? Pin
Le@rner21-Dec-08 22:05
Le@rner21-Dec-08 22:05 
GeneralRe: How can change CRect Value? Pin
Code-o-mat21-Dec-08 22:43
Code-o-mat21-Dec-08 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.