Thomas Cunningham wrote: > > You don't need to "see what works". > > Sure I do or else my declare sometimes does not function as > described in the > docs. I've come across quite a few declares where only one of these three > choices does work and the others fail (crash). My experience is that it is > not clear cut which one to use and was looking for some guidance. > There is a > lot of trial and error using declares in Rb, at least for me as a non-c > programmer.
My point was that this should be a very clear choice. Especially when deciding between "as Ptr" and "ByRef as Ptr". They're worlds apart. On the other hand, "as Ptr" and "as MemoryBlock" are practically equivalent. Some guidance: > float domain[2]; > float range[8]; float is a 4-byte entity, so the equivalent MemoryBlocks are domain= new MemoryBlock(8) range = new MemoryBlock(32) You can declare them as Ptr or as MemoryBlock. It doesn't matter when you are passing them TO a declare. When you're getting them BACK from a declare, and you want to manipulate them, then a MemoryBlock is easier to deal with. It's all the same to the declare. In C, you declare it like "float domain[2]" (essentially a MemoryBlock), and you pass it like "float *domain" (a Ptr). Where you get into trouble is with ByRef. That adds another level of indirection, and will crash your program if you get it wrong. Fortunately, it's pretty straightforward. The following are "as Ptr" or "as MemoryBlock". They are each a pointer to a chunk of memory. float domain[2]; float domain[]; float *domain; The following are "ByRef as Ptr" or "ByRef as MemoryBlock". They are each a pointer to an array of pointers to chunks of memory. float *domain[2]; float *domain[]; float **domain; These are the most commonly used scenarios. There are a few more exotic ones, but they are much less common. If you follow the pattern, even a non-c programmer should stay pretty safe. I honestly hope that is helpful. Tim No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.6.2/781 - Release Date: 4/30/2007 9:14 AM _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
