New topic: 

Call By Value Fails for Arrays

<http://forums.realsoftware.com/viewtopic.php?t=35350>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        B0B          Post subject: Call By Value Fails for ArraysPosted: 
Wed Sep 08, 2010 10:18 pm                         
Joined: Sun Mar 05, 2006 5:29 am
Posts: 81                Is there any way to pass an array by value to a 
subroutine? I thought maybe I could put an array inside a structure and pass it 
that way, but RB won't let me put an array into a structure.      
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                             Top                npalardy          Post subject: 
Re: Call By Value Fails for ArraysPosted: Wed Sep 08, 2010 11:04 pm             
            
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 6048
Location: Canada, Alberta, Near Red Deer                No - their contents 
will always be mutable in any called routines      
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                             Top                B0B          Post subject: Re: 
Call By Value Fails for ArraysPosted: Thu Sep 09, 2010 12:06 am                 
        
Joined: Sun Mar 05, 2006 5:29 am
Posts: 81                Okay thanks.

In that case maybe you could suggest an alternative. Here's my problem. I have 
a recursive routine to which I need to pass a 30x30 array of Int8. I could copy 
the array every time I enter the routine, but that strikes me as very 
inefficient, especially since speed is critical in this routine. I'd thought 
about representing the array as a string, but since I need to do some math on 
the values, there is the overhead involved converting data. As I mentioned, 
speed is the primary concern. Any ideas would be appreciated.      
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                             Top                jefftullin          Post 
subject: Re: Call By Value Fails for ArraysPosted: Thu Sep 09, 2010 3:48 am     
                            
Joined: Wed Nov 15, 2006 3:50 pm
Posts: 1839
Location: England                Quote: I have a recursive routine to which I 
need to pass a 30x30 array of Int8

Use a memory block of 900 bytes

value (x,y) =  memoryblock.uint(x*30 +y)


if you are doing things in a loop, you can precalc x*30 which also increases 
the speed.
But frankly, you'll be hard pushed to notice the difference in such a small 
array.      
_________________
RB2009 R5.1 and RB2008
Mac 10.6 + Windows 7/XP  + Ubuntu Linux in Vmware
on a Macbook 2.16  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to