G
Guest
Sorry to bring up a topic that is just flogging a dead horse.... but...
On the topic of memory management....
I am doing some file parcing that has to be done as quick as posible,
but what I have found hasnt been encouraging...
I found that the *quickest* way is to use a struct to retrieve fixed length
packets out of the file, but structs get placed on the stack! In one of the
books I read, the stack is only about 1mb, so I would rather it not go there.
(Not that there is even enough space to do what I want it to do.)
If I put all, say, 5000+ records on the heap individualy, then the heap has
to work quite hard every time it has to house cleaning.
So finaly, I see two "good" options remaining: Allocate one block of memory
on the managed heap, or a block of memory on the unmanaged heap. From
what I have read, if I allocate a chunk on the managed heap, and then want
to use pointers on it, I would definitly need to fix the allocated memory via
fixed() or pinning via GCHandle. The other option is to use unmanaged memory.
I have also read that pinning hurts the process of garbage collection, but in
another book, I read that big allocations typicaly dont get moved around.
My questions are as follows:
Q1)
Is using fixed or is pinning an object the same thing?(Ignoring the fact
that the memory is reliesed at the end of the fixed statement, and the
pinnin is unpinned when I say it is.) Any good reasons to use pinning over
fixed??
Q2)
Is pinning all that bad for an object that "probably won't move" anyhow?
Q3)
Would using unmanaged memory be better in this case?
(yes I know that I would have to be careful to prevent leaks.)
Q4)
Does unmanage memory ever move? (eg no fixing req?)
Q5)
Does the managed heap actualy get derived from the unmanaged?
If so, how much memory at a time? and is the managed heap
always contiguous from one end to the other?
Q6)
I heard that the generics class list<T> has some wonderful performance
gains, and is a lot easier on the heap than the ArrayList. Mostly I have heard
that its performance gains are due to the lack of boxing and unboxing. Does
it allocate chunks of memory on the heap preventing zilions of objects
floating
around the managed heap too?
Q7)
"Bitmap data is allocated on the heap." Why?
I have heard so many conflicting stories about the unmanaged heap, so I am
lift
in the dark not knowing the "real" story.
Thank you for any and all your help on this topic.
On the topic of memory management....
I am doing some file parcing that has to be done as quick as posible,
but what I have found hasnt been encouraging...
I found that the *quickest* way is to use a struct to retrieve fixed length
packets out of the file, but structs get placed on the stack! In one of the
books I read, the stack is only about 1mb, so I would rather it not go there.
(Not that there is even enough space to do what I want it to do.)
If I put all, say, 5000+ records on the heap individualy, then the heap has
to work quite hard every time it has to house cleaning.
So finaly, I see two "good" options remaining: Allocate one block of memory
on the managed heap, or a block of memory on the unmanaged heap. From
what I have read, if I allocate a chunk on the managed heap, and then want
to use pointers on it, I would definitly need to fix the allocated memory via
fixed() or pinning via GCHandle. The other option is to use unmanaged memory.
I have also read that pinning hurts the process of garbage collection, but in
another book, I read that big allocations typicaly dont get moved around.
My questions are as follows:
Q1)
Is using fixed or is pinning an object the same thing?(Ignoring the fact
that the memory is reliesed at the end of the fixed statement, and the
pinnin is unpinned when I say it is.) Any good reasons to use pinning over
fixed??
Q2)
Is pinning all that bad for an object that "probably won't move" anyhow?
Q3)
Would using unmanaged memory be better in this case?
(yes I know that I would have to be careful to prevent leaks.)
Q4)
Does unmanage memory ever move? (eg no fixing req?)
Q5)
Does the managed heap actualy get derived from the unmanaged?
If so, how much memory at a time? and is the managed heap
always contiguous from one end to the other?
Q6)
I heard that the generics class list<T> has some wonderful performance
gains, and is a lot easier on the heap than the ArrayList. Mostly I have heard
that its performance gains are due to the lack of boxing and unboxing. Does
it allocate chunks of memory on the heap preventing zilions of objects
floating
around the managed heap too?
Q7)
"Bitmap data is allocated on the heap." Why?
I have heard so many conflicting stories about the unmanaged heap, so I am
lift
in the dark not knowing the "real" story.
Thank you for any and all your help on this topic.