Page 2 of 3

Re:Help with Cryptic C++ code

Posted: Thu Jan 19, 2006 8:03 am
by Candy
Solar wrote: Col. Kernel is right, though - STL style allocater functions would be a point where placement new would come in handy.
Well... any time you wanted to place an object in memory you control separately. That includes allocators and shared memory.
I've never seen anyone actually using the option of defining your own allocator functions, either... (You'd probably do this if you were optimizing like hell, but who does these days where labor is expensive, but better hardware is cheap...) ;)
I'll be at Breakpoint 2006, I promise.

It came in handy when trying to cut down on memory requirements for a large linked list or tree of one object type, so I made a separate allocator and used it. I can't stand people making algorithmic improvements and completely ignoring plain common sense.

Re:Help with Cryptic C++ code

Posted: Thu Jan 19, 2006 8:40 am
by Solar
Candy wrote: It came in handy when trying to cut down on memory requirements for a large linked list or tree of one object type, so I made a separate allocator and used it. I can't stand people making algorithmic improvements and completely ignoring plain common sense.
No doubt and 100% ACK. But here at work our production server is running debug code because the additional testing of release code would cost more than the additional bits of RAM and CPU cycles... the beautiful difference between "business" and what you would like to do...

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 2:55 am
by Neo
In some other similar code (it used a multimap)
I saw that within the for loop the iter variable was used with a member 'second' as in

Code: Select all

iter->second;
Any idea what this 'second' refers to?

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 3:15 am
by Solar
Check the documentation for the "pair" container. A pair has two elements, pair->first and pair->second.

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 3:47 am
by Neo
Oh! I was looking at the multimap members and could not find any 'second' there.
Thanks Solar.

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 3:58 am
by distantvoices
@candy&solar: You tell how it's been at breakpoint 2006, yeah?

Some photostory. *gg*

It's a pity I canna show up there, but for one I have to attend university and for second I have to go to work *?rks* (and not too much free days left, eh?)

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 4:04 am
by Solar
Neo wrote: Oh! I was looking at the multimap members and could not find any 'second' there.
I strongly recommend the library references available at http://www.dinkumware.com, if for nothing else but their fully searchable index. 8)

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 4:15 am
by Neo
Err.. ?????

Re:Help with Cryptic C++ code

Posted: Mon Feb 20, 2006 4:26 am
by Solar
Well, Ctrl-F on the Dinkumware C++ reference index and searching for "second" would have given you three "hits":
  • binary_function::second_argument_type
  • pair::second
  • pair::second_type
I assume you would have been able to find out what that iter->second meant, given the above result.

Besides, it's a very useful reference in any case - if simply because you can have it on file instead of carrying a hardcopy around. ;)

Re:Help with Cryptic C++ code

Posted: Tue Feb 21, 2006 9:06 am
by Neo
Neo wrote: Err.. ?????
That was to beyond_infinity's post.

Re:Help with Cryptic C++ code

Posted: Tue Feb 21, 2006 9:08 am
by Solar
Ah... Breakpoint 2006 is where Candy, Pype and myself will meet each other the first time in person. BI was referring to Candy's earlier reference to that upcoming occasion.

Re:Help with Cryptic C++ code

Posted: Tue Feb 21, 2006 9:11 am
by Neo
Anyway a quick question on multimap iterators.
Multimaps allows more than I element with the same key.
So if I traverse through the list how does it go through the elements in the list (I can't test this out because my CYGWIN g++ is acting funny when I try to declare a multimap)

Re:Help with Cryptic C++ code

Posted: Tue Feb 21, 2006 9:53 am
by Solar
When constructing a multimap, you can pass to the constructor a function object (predicate) that does the ordering. By default, this is [tt]less[/tt], meaning that, if you get two elements X, Y with X->first == Y->first, you will get one after another, but the exact order is unspecified (as neither is "less" than the other). This is called "strict weak ordering".

Re:Help with Cryptic C++ code

Posted: Wed Feb 22, 2006 2:23 am
by distantvoices
@NEO: if you have a problem with what I am posting you may as well consider talking to me in plain sentences so we can speak about the problem and get rid of the one or other difference, ok?

stay safe

Re:Help with Cryptic C++ code

Posted: Wed Feb 22, 2006 10:27 pm
by Neo
@beyond_infinity: Now what was that all about?