Branimir said:
........
I think that just reading following is enough
"
Most everyone says GC is or should be slower, with no given reason- it's
assumed but never discussed. Some computer language researchers say
otherwise.
Consider what happens when you do a new/malloc: a) the allocator wanders
through some lists looking for a slot of the right size, then returns you a
pointer. b) This pointer is pointing to some pretty random place.
Isn't this compiler/platform specific? I don't think modern compilers
wander through looking for specific memory sizes, it's easier to keep
two pointers, one is to a stack of deallocated space, the other to the
beginning of unallocated heap. The stack should be fairly short, and
can be traversed very quickly, then begining of heap, then allocates a
space the right size, if there is not enough space, it asks the OS for
another block. After 30 years, these routines are well tuned, and about
as fast as you can get.
With GC, a) the allocator doesn't need to look for memory, it knows where it
is, b) the memory it returns is adjacent to the last bit of memory you
requested. The wandering around part happens not all the time but only at
garbage collection. And then of course (and depending on the GC algorithm)
things get moved of course as well.
A garbage collector really has the same process at work, in the case of
Java, the GC determines when a portion of memory is deallocated. Some
GC's might also merge small adjacent blocks together, and shift
allocated blocks to try and minimize fragmentation. However this
introduces another problem, the application and GC then need to be
synchronized so that the GC isn't moving a block that the application is
using, and this introduces overhead for both. With modern computers
having huge memory resources, the overhead of packing memory isn't
really worth it.
Actually with C/C++ you can eliminate the new/malloc, simply allocate a
pointer called mem_head, malloc it some large amount of memory say 64MB.
Now allocate a second pointer called mem_cur set this equal to mem_head
, when you want memory do something like this:
int *my_ptr;
my_ptr = mem_cur;
mem_cur+=sizeof(int);
Now you have allocated the size of an int block of memory to my_ptr;
Yeah you will waste memory you would normally deallocate, but that is
the price you pay for speed.
At the end of the program simply call free or delete mem_head.
Try doing that with a Garbage Collector!!!!
Cracking DES, your probably best to write it in, uh, um assembler....
Paul