electro-music.org   Dedicated to experimental electro-acoustic
and electronic music
 
 Front Page  |  Radio  |  Forum  |  Media  |  Playlists  |  Wiki
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Array Size
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
charley



Joined: Sep 03, 2008
Posts: 8
Location: San Francisco, CA

PostPosted: Wed Sep 03, 2008 3:41 pm    Post subject: Array Size Reply with quote  Mark this post and the followings unread

Hi Everyone,

I'm new here and a fellow ChucK addict.

How do I get the size of a multidimensional array? I'm passing a multidimensional array to a function in a new class and I want that function to determine the array size.

I'm writing a very simple non-uniform random number generator that will use multi-dimensional array containing target numbers and weights (propability of selection).

For example, here's skeleton code.

Code:
// Non-Uniform Random Generator
class Nurg
{
    int weightMap[][];

    public void SetMap ( int newMap[][])
    {
        newMap @=> weightMap;
    }
}


[ [ 0,1 ], [1,1], [2,3], [3,3], [4,1], [5,1], [6,1] ] @=> int myWeightMap[][];

Nurg myNurg;
myNurg.SetMap (myWeightMap);


So how can I know the size of the newMap array inside my SetMap function?

Sorry if this is a silly question. I'm just starting to learn..

Thanks Smile
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Sep 03, 2008 3:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

Well,
Code:

newMap.cap()


Will give you the size of the first dimension. The length of the others need not be the same but


Code:

newMap[0].cap()


Will give you the size of the first, which will be the size of the others as well if you never change their length.

Does that help?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Sep 03, 2008 3:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

Oh, and welcome on board!
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
charley



Joined: Sep 03, 2008
Posts: 8
Location: San Francisco, CA

PostPosted: Wed Sep 03, 2008 3:52 pm    Post subject: Reply with quote  Mark this post and the followings unread

Wow! An answer in EIGHT minutes? You can't even get that from commercial tech support.. hehe..

Thanks Kassen.. You're awesome..

-Charley
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Sep 03, 2008 6:17 pm    Post subject: Reply with quote  Mark this post and the followings unread

You were lucky, I'm off to bed now so the next answer from me may take 8 hours. Clearly we need ChucKists in more time-zones for strongly timed answers! :¬)
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Log in
Username:     Password:      Log me on automatically each visit    


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2026 by electro-music.org