• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. how to declare an array of unknown size

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 143
  • Views 25549
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to declare an array of unknown size

Sri Charan B
Sri Charan B over 13 years ago

Hi,

I am trying to implement a code where i came in need of an array which can increase the size of the array during the runtime. I mean the size of the array shall not be declared using the 'declare' command but during the run time if new elements are to be added into that array i will use it or else the array shall be empty.

I need this because i am at a juncture where i cannot expect or fix the size of the array to a particular value so guys please help me.

Thanks in advance for any help,

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I'm not 100% certain what you're after. First of all, arrays can be declared on the fly - so you can create arrays with the size based on a variable - if that's what you want, that's easy. For example, this code here provides a way to create multi-dimensional arrays simply:

    /* abMultiDimArray.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Nov 23, 2009 
    Modified   
    By         
    
    Function for creating a multi-dimensional array.
    
    Usage:
    
    data=abMultiDimArray(6 8)
    
    Creates a 6 by 8 array (starting index is from 0). Then you can use:
    
    data[4][5]=23
    data[0][7]=123
    
    You can specify more dimensions by passing more arguments to abMultiDimArray.
    
    ***************************************************
    
    SCCS Info: @(#) abMultiDimArray.il 11/23/09.16:24:27 1.1
    
    */
    
    procedure(abMultiDimArray(@rest dimensions)
        let((arr)
            if(integerp(car(dimensions)) && plusp(car(dimensions)) then
                arr=makeVector(car(dimensions))
                when(cdr(dimensions)
                    for(ind 0 sub1(car(dimensions))
                        arr[ind]=apply('abMultiDimArray cdr(dimensions))
                    )
                ) ; when 
                arr
            else
                error("Dimension %L must be a positive integer\n" car(dimensions))
            ) ; if
        ) ; let
    ) ; procedure

     

    If however you're asking for a way to declare an array of a certain size, and then make it bigger later, then I would question whether you really want an array. You could either use a list for this dynamic data structure, or you could use a hash (association) table. Which you would use depends on how it is going to be accessed. Lists are good if you can traverse them sequentially, but not good if you want to access the data in a random-access fashion (e.g. you want to access the 10th, or the 15th, or the 2453th entry arbitrarily). Hash tables are good if you want to access the data with random access, but no good if you want any kind of order.

    A table could be created using:

    myArr=makeTable('myArray)

    and then you could use:

    myArr[0]=1
    myArr[1]=2

    and you can arbitrarily add indices later - they can be sparse too - so doing myArr[123456789]=3 is perfectly OK and doesn't have to allocate all the space for the intervening indices. The downside is that the keys are not in any order - so doing myArr->? would give you the keys in some arbitrary order - but provided you're treating it like an array, that shouldn't be an issue.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I'm not 100% certain what you're after. First of all, arrays can be declared on the fly - so you can create arrays with the size based on a variable - if that's what you want, that's easy. For example, this code here provides a way to create multi-dimensional arrays simply:

    /* abMultiDimArray.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Nov 23, 2009 
    Modified   
    By         
    
    Function for creating a multi-dimensional array.
    
    Usage:
    
    data=abMultiDimArray(6 8)
    
    Creates a 6 by 8 array (starting index is from 0). Then you can use:
    
    data[4][5]=23
    data[0][7]=123
    
    You can specify more dimensions by passing more arguments to abMultiDimArray.
    
    ***************************************************
    
    SCCS Info: @(#) abMultiDimArray.il 11/23/09.16:24:27 1.1
    
    */
    
    procedure(abMultiDimArray(@rest dimensions)
        let((arr)
            if(integerp(car(dimensions)) && plusp(car(dimensions)) then
                arr=makeVector(car(dimensions))
                when(cdr(dimensions)
                    for(ind 0 sub1(car(dimensions))
                        arr[ind]=apply('abMultiDimArray cdr(dimensions))
                    )
                ) ; when 
                arr
            else
                error("Dimension %L must be a positive integer\n" car(dimensions))
            ) ; if
        ) ; let
    ) ; procedure

     

    If however you're asking for a way to declare an array of a certain size, and then make it bigger later, then I would question whether you really want an array. You could either use a list for this dynamic data structure, or you could use a hash (association) table. Which you would use depends on how it is going to be accessed. Lists are good if you can traverse them sequentially, but not good if you want to access the data in a random-access fashion (e.g. you want to access the 10th, or the 15th, or the 2453th entry arbitrarily). Hash tables are good if you want to access the data with random access, but no good if you want any kind of order.

    A table could be created using:

    myArr=makeTable('myArray)

    and then you could use:

    myArr[0]=1
    myArr[1]=2

    and you can arbitrarily add indices later - they can be sparse too - so doing myArr[123456789]=3 is perfectly OK and doesn't have to allocate all the space for the intervening indices. The downside is that the keys are not in any order - so doing myArr->? would give you the keys in some arbitrary order - but provided you're treating it like an array, that shouldn't be an issue.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information