just a few small questions

David Medlock noone at nowhere.com
Fri Apr 21 17:50:51 PDT 2006


Chris Nicholson-Sauls wrote:
> MM wrote:
>>> I think you are best off using the heap for your large global array. 
>>> Data placed on the heap stays there until you explicitly delete it, 
>>> so you don't have to use a global. Heap is also what you use if you 
>>> have any sort of dynamic memory needs, you can allocate what you need 
>>> when you need it. If you use new/delete to much, the heap may become 
>>> segmented and then the garbage collector will run (I think). The heap 
>>> is unlimited for the most part, while you can only allocate so much 
>>> data onto the stack. The heap might be slower to access, but not 
>>> enough to be a significant problem.
>>>
>>> Maybe an expert can vindicate my post?
>>> ~ Clay
>>
>>
>> Why is wrong with using a Global? When I need an array for the whole 
>> time and
>> more than half of the subs need to access it, I just don't want to use 
>> those
>> annoying pointers the whole time :).. how is this done in D?
>>
> 
> Pointers, schmointers.  You can pass an array as normal to a function 
> without copying. (This is where the Copy-on-Write people might speak 
> up.  I'll let them.)  Also, if you intend to replace the array during a 
> function, just use an 'out' or 'inout' parameter.
> 
> Although personally I have no problem with using globals.  :)
> 
> -- Chris Nicholson-Sauls


if by replace your mean modify the array itself, no 'out' is needed 
since arrays are passed by reference, just like objects.

If you want to change the *variable* in the calling function, then an 
(in)out is needed.

-DavidM




More information about the Digitalmars-d-learn mailing list