Hi,
Wondering can you help me with this one. I'm translating some C into
C# and have come accross the following line of code in C:
free(A)
where "A" is an array of type double.
No, "A" isn't an array of type double, if it is properly used in your
free(A);
statement
I'm trying to translate/
approximate that line into C# and am wondering what is the nearest
equivalent? I know "free()" function frees up some memory in C [snip]
Does free reset the elements of the array? If so i could reset them
all to zero or just deleted everything in the array...
Well, we can't answer C# questions; that would be a job for a newsgroup
dedicated to C#. You could ask the C# part of your question in
microsoft.public.dotnet.csharp.general or one of the other C# newsgroups
As for free(A), it returns to a "freepool" a block of storage allocated
using one of the alloc() functions. To figure out what the C# equivalent of
free() is, you probably need to know what the C alloc() and free()
functions do. Our resident experts can answer that one better than I.
However, I'll give it a try and let them correct me. ;-)
You start with a variable that is defined as a pointer (of some type).
Initially, this variable points nowhere; you can't use it to store or
retrieve information yet. However, what you do is set this pointer to the
value returned by an alloc() call; the alloc() call will allocate an amount
of memory from a pool of available memory (I'll call this a "freepool"),
and will return a pointer to the beginning of that allocated memory. The
memory block is of fixed size (the size you asked for as part of the
alloc() call, and is aligned in such a manner that any data type can
properly sit in the block.
Now, your variable points to a block of memory. You can use this block of
memory like an array. You can pass the pointer around, make copies of it,
and do pretty much anything with it and the memory that you could do with a
variable that had been allocated through the builtin manners ("auto"
or "static" or the default).
When you are done with the block of memory, you pass the original pointer to
the free() function, which does it's magic. You aren't concerned
about /what/ magic it does (it usually "returns" the block to a "freepool"
where it might be given out to another alloc() call; it /might/ initialize
the block to a fixed value, but it probably doesn't); you only know that
the specific pointer value you had is now unusable (any other pointers
derived from that pointer value are likewise unusable), and the storage
space the pointer(s) pointed to is no longer available for your use.
HTH
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------