Thread: What would be the best way to name these typedefs?

  1. #46
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by laserlight View Post
    Did you really find the occasional reallocation due to expansion of vector to be a bottleneck, in general?
    Since you asked about vector in general, not about vector of strings, yes, I was forced to write a memory allocator which prevented fragmentation. The idea was common and simple, it was using larger chunks for small and fixed size memory blocks. Deque could quickly acquire specified block of memory (in logarithmic time), while vector had not only to copy data but also use slower new/delete as it grew in size.

    I am arguing that you must have a reason for it, such as inserting at the beginning of a vector.
    This, along with other benefits, is why I prefer deque as a general-purpose container for strings.

  2. #47
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by kmdv View Post
    Since you asked about vector in general, not about vector of strings, yes, I was forced to write a memory allocator which prevented fragmentation. The idea was common and simple, it was using larger chunks for small and fixed size memory blocks. Deque could quickly acquire specified block of memory (in logarithmic time), while vector had not only to copy data but also use slower new/delete as it grew in size.
    It sounds like vector was a poor choice of a container in that situation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #48
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Can I for sure? No.
    Can I make an educated guess? Yes.
    Is it radically slower? I don't know. Is it slower? Yes, probably. By how much? I don't know
    That type of answer is indicative of a negligible difference in speed. If you've used deques and vectors in the same place, you've probably never been arsed to profile the difference. Even if you did, the difference is on order of a few milliseconds in real time, just to travel to different blocks perhaps. That is not 'radical' compared to vector.

  4. #49
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well no, I did not say it was a radical difference for vector vs deque. Only that deque would be slower. IIRC.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #50
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    He asked about any problems with vector, thus I gave a specific problem.
    It's individual expierience with containers. I had some bad experiences with vector expanding and memory fragmentation, and I will keep using deque for strings unless I have a reason, since I think it's just unnecessary to use vector. Since we have no specific problem, I can't see any point in continuing this.

  6. #51
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by Elysia View Post
    Well no, I did not say it was a radical difference for vector vs deque. Only that deque would be slower. IIRC.
    Sorry for continuing, but you can't just say that deque would be slower. You can often push data, and access it very rarely. Vector has yet another problem - reallocation will not happen if you remove 95% of elements, in deque the unused memory can be freed.

  7. #52
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    Well no, I did not say it was a radical difference for vector vs deque. Only that deque would be slower. IIRC.
    So, by saying this...

    Quote Originally Posted by Elysia View Post
    What I mean is that Big-oh time is not the same as real time.
    Take a vector and linked list an example. Insert an element at the end in both containers. Both as O(1), but the vector is radically faster, nevertheless.
    Constant time is a convenient term when comparing algorithms, but is only good for a starting guess. I can easily write two different algorithms with the same Big-oh time, but one radically faster than the other.
    you either mean to patronize me, by assuming I have no idea what asymptotic notation is for, or you were saying that there was a radical difference between the two algorithms we were comparing. I'm sorry I was wrong, but I do not like the alternative interpretation any better. Saying the difference was negligible is a safe statement, unless you are prepared to dream up a situation where the difference in access time between vector and deque is a bottleneck.

  8. #53
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by kmdv View Post
    Sorry for continuing, but you can't just say that deque would be slower. You can often push data, and access it very rarely. Vector has yet another problem - reallocation will not happen if you remove 95% of elements, in deque the unused memory can be freed.
    And you can't say a vector is slower. It all depends on how and where you use it.
    The only difference between us is the standard container we use. I use vector, you use deque.
    I simply don't feel it's worth the difference to switch over to deque due to strings because I cannot put forth a good enough theoretical guess that it will be faster.
    I would simply have to measure performance in my program if I needed it, and choose based on that.

    Quote Originally Posted by whiteflags View Post
    So, by saying this...
    you either mean to patronize me, by assuming I have no idea what asymptotic notation is for,
    Absolutely not. My comments were based on the fact that you understood what asymptotic notation is. We are both programmers.

    ...or you were saying that there was a radical difference between the two algorithms we were comparing. I'm sorry I was wrong, but I do not like the alternative interpretation any better. Saying the difference was negligible is a safe statement, unless you are prepared to dream up a situation where the difference in access time between vector and deque is a bottleneck.
    The thing is that that was a general statement. Not a comparison with vector and deque.
    Which was kind of my point. Of many, I guess.

    The performance between a deque and vector is very similar (unless you count inserting at the beginning of a vector), that the Big-oh times for handling strings in a deque and vector would be the same. Therefore, I cannot make a very good guess as to which would be faster for my usage of strings. Therefore, I would not bother switching over to a deque unless I hit performance constraints in my program.

    Sorry if I come off as rude or patronizing.
    Last edited by Elysia; 02-20-2011 at 01:16 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Typedef's
    By valaris in forum Windows Programming
    Replies: 2
    Last Post: 04-25-2009, 09:32 AM
  2. pointer to function and typedefs
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2006, 07:37 AM
  3. Standard typedefs ...
    By twomers in forum C++ Programming
    Replies: 6
    Last Post: 02-16-2006, 10:07 AM
  4. how to use typedefs with structs?
    By Yourhighness in forum C Programming
    Replies: 9
    Last Post: 06-03-2003, 04:43 AM
  5. Using TypeDefs
    By peking1983 in forum C Programming
    Replies: 2
    Last Post: 03-14-2003, 01:26 AM