Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Feb 2006
Offline Last Active Apr 25 2013 11:52 AM

Posts I've Made

In Topic: Possible neutrinos travel faster than light

26 September 2011 - 10:16 AM

Uh, Photons do too reach the maximum speed of light.....Photons are massless particles that move unhindered because gravity only exerts a pull upon things with mass....

That's not true. Photons DO have a mass, however they don't have a rest mass (I hope this is the right word, in german it's called "Ruhemasse"). If photons had no mass then light could not be bent, however it is possible in extremely strong gravitational fields. These kinds of distortions are actually used to detect black holes (the quiet ones ;) ).


I can't find an english source, but this (beware, german) is what I'm talking about. But according to that source, "bewegte masse" (moving mass, or something like that) just seems to be another word for energy. It renders my comment somewhat pointless :)

In Topic: Winsock difficulties

26 September 2011 - 12:33 AM

HP: Your hostility is unbelievable. I came to this forum seeking knowledge, not abuse.

I didn't hear such a hostility. He gave you a hint to where to find such knowledge (eg. the library) ;)

Once you have a better understanding of the means of communication you can come back to actually implement it.

In Topic: Question on Threads

22 September 2011 - 06:24 AM

Yes it will work. Most operating systems will use some sort of scheduling in order to let each thread run a little, before it will be swapped for another one. For example, my computer at work has about 1150 threads running (with just a view actually doing stuff).

In Topic: Deleting a Large "list",

21 September 2011 - 01:25 AM

I actually meant the destructor of your Token class. Calling delete(*iter) first calls the destructor of your Token object and then frees the memory associated with it. Depending on the Token object and the amount of work the destructor must do, it can take some time. But this totally depends. If you want to continue using the list class then I suggest you look into custom allocators and memory pooling. You could advise the pool to reserve a large amount of memory upfront (for example 10mb) and then use that pool instead of the default allocator (which simply uses new for allocating a node within a list).

Another option would be to skip visual studio's memory allocator alltogether and use a better one: http://www.hoard.org/ We are using hoard at work and it has proven to be several times faster than the one visual studio provides.

In Topic: Deleting a Large "list",

21 September 2011 - 12:34 AM


I've got a very large list of pointers. The pointers point to new-d objects. I need to free all the objects and then delete the list (which is itself new-d). My current technique looks like:[source lang="cpp"]for (list<Token*>::iterator iter=_tokens->begin();iter!=_tokens->end();++iter) { delete (*iter);}delete _tokens;[/source]Unfortunately, the "delete _tokens;" line takes a very long time (about ten times longer than loading the data into the list in the first place, doing lexical analysis, and parsing, all put together). Clearly, this is problematic. I have tried "_tokens->clear();" before the delete, but then that line takes forever instead. I have also tried manually removing all the elements one by one with a loop, but then that loop takes too long.

Help? Thanks,

You have to release that memory, unless you want to leak it. There is no way around it. Your way of doing it seems fine (although I wouldn't use raw pointers in containers): If you want it to be faster then you need to start profiling your code. Some hints:

-You haven't told us what very large means to you
-What is your destructor doing?
-What compiler (gcc/msvc, debug/release, what optimizations), etc...
-Have you tried another data structure? (std::vector comes into mind)
-Have you looked into using memory pools (eg. custom allocators, etc..)?

*edit* You should think about your code before randomly writing code. Calling _tokens->clear() is WRONG. Your list is empty afterwards and therefore the loop doesn't do anything and therefore you are now leaking memory.