Resize an array

Hi,
Is it possible to resize an array of objects ? I create an array of 10000 objets. But I need ,after more calculations , only 8000 objects. Is it possible to resize the original array without create another array and copy the original in the new array ?
Thank you for your help
Marcel

No, you cannot resize arrays in java.
The simplest thing to do is use one of the List implementations. ArrayList and LinkedList both provide
the appearence of resizable structures. (ArrayList contains an array which it automatically resizes for you
(by copying) which LinkedList is inherently dynamic in size (but slow to perform indexed get operations
on)
matfud

Similar Messages

  • Resizing an array of struct inside a DLL using the memory manager

    Hi all,
    I dug deep inside the boards, but wasn't able to find a solution for my problem.
    I'm building a dll, which does some imageprocessing and should return an array of structs to labview, with one struct for every element in the image.
    As I don't know the number of elements beforehand and the limit of the number is numbers of magnitude larger then the expected one, I don't want to allocate such a huge chunk of memory prior to the dll call in labview.
    In a former version I used a 2d array for the elements, where each row holds the values of every element. Here I used the NumericArrayResize-function, which worked quite well. But I have to add more sub-processes and using structs (or clusters in labview) appears to be more usefull and cleaner for me, in addition I had to cast some of the elements back and foreward a few times.
    So one element-struct should hold 2 singles and 1 uint32. My question is now, how can I resize this array of struct with memory manager functions as the NumericArrayResize-functions does not suit this purpose?
    (Accessing a given array of structs inside the DLL and after that reading the changed values in Labview is surprisingly easy )
    Thanks in advance
    Solved!
    Go to Solution.

    Well, I was able to solve it myself. I found this thread, where the first post of rolfk made me thinking. It appeared to me, that the numericarrayresize-function behaves very similar to the realloc-function of c. So I used the type unsigned int 8 (which is just one byte) and multiplied it by the number of bytes used by one struct, in my case 12 bytes (4+4+4) and then multiplied it by the number of structs (elements in the image) i have. Luckily it worked and the memory block was resized exactly as I wanted it to be. Important to note: do not forget to adjust the size element of the handle, otherwise Labview does not know about the changed size.

  • How can I resize an array of strings?

    I'm having a problem of not being able to use the CIN functions and therefore can't use the convenient resizing methods. I have tried to use NumericArrayResize to resize an array of strings, but it's not working correctly. Here's what I've tried most recently. I have tried many variations, so if you want to modify what I have posted, or just provide new code, please feel free.
    typedef struct {
    int32 dimSize;
    LStrHandle elt[1];
    } LStrHandleArray;
    typedef LStrHandleArray **LStrHandleArrayHandle;
    void someMethod(LStrHandleArrayHandle arrayOut) {
    // attempting to write the string "asdf" in the first element in the array. (1D array)
    int newSize = 1;
    MgErr e = NumericArrayResize(uL, 1L, (UHandle*)&arr
    ayOut, newSize);
    (*arrayOut)->dimSize = newSize;
    LStrHandle hdl = *(*arrayOut)->elt;
    long str_size = strlen("asdf");
    MgErr err = NumericArrayResize(uB, 1L,(UHandle *)&hdl, str_size);
    LStrLen(*hdl) = str_size;
    MoveBlock("asdf", LStrBuf(*hdl), str_size);
    The code above doesn't result in crashing labview at any time. The string "asdf" is not copied though. And, after being able to copy one string I would like to extend this to many elements in a 1D array of strings.
    Thanks!
    Naveen

    LabVIEW stores string arrays as an array of handles to those strings. To resize an array of strings you need to declare a new string in LabVIEW's data space, resize the handle array, and add a handle to your new string. Here is an example program which does this.
    -Aaron Marks
    National Instruments
    Attachments:
    resize.zip ‏252 KB

  • Resizeing an array of LStrHandles within Call Library Functio Node crashes SubVI.

    Hello,
    I try to resize an array of LStrHandles within a shared library. Here the C-code - attached a picture of the calling SubVI:
    /* Call Library source file */
    #include <stdio.h>
    #include "extcode.h"
    /* Typedefs */
    typedef struct {
            long dimSize;
            LStrHandle elt[1];
            } TD1;
    typedef TD1 **TD1Hdl;
    long strArray(TD1Hdl arg1);
    long strArray(TD1Hdl arg1)
            long err=0, count=2;
            err = DSSetHandleSize((UHandle)arg1, sizeof(long) + count*sizeof(LStrHandle));
            if(err) {
                    printf("ERROR: 'DSSetHandleSize()': %ld\n", err);
                    return err;
            (*arg1)->dimSize = (*arg1)->dimSize;
            return noErr;
    I know there are a lot of threads, I read some and also tried the provided source code but somehow LabVIEW crashes. I don't know if it is valueable but when I change the following line it does not crash:
    (*arg1)->dimSize = (*arg1)->dimSize;
    Thanks for any help,
    Johannes
    OS: RedHat
    LV: 8.2 Prof
    Message Edited by [email protected] on 03-11-2009 12:26 PM
    Solved!
    Go to Solution.
    Attachments:
    subvi-resize-stringarray.jpg ‏7 KB

    To be honest I'm not fully sure why that would crash but proper dealing is a lot more complicated than what you have done. The crash probably happens not in the C fucntion but on return of the function as LabVIEW tries to display the data. DSSetHandleSize() does not initialize the area it allocates additionally so there is likely garbage which LabVIEW then tries to interpret as string handles and consequently crashes.
    You should also use NumericArrayResize() whenever possible as it takes care of various complications that can be hard to deal with on multi platform programs. NumericArrayResize() does use internally DSSetHSzClr() which initializes additional memory to 0. That would avoid the crash since LabVIEW does interpret NULL handles as the default for the according datatype, which would be here an empty string.
    #include "extcode.h"
    #if  IsOpSystem64Bit
    #define uPtr uQ
    #else
    #define uPtr uL
    #endif
    typedef struct {
        int32 dimSize;
        LStrHandle elm[1];
    } TDStrArr, **TDStrArrHdl;
    MgErr MyArrayFunc(TDStrArrHdl arr)
        int32 count = 4;
        LStrHandle p;
        MgErr err = noErr;
        /* The array could be non empty so dispose of any elements in it that are bigger than what we need */
        for (i = (*arr)->dimSize - 1; i >= count; i--)
          p = (*arr)->elm[i];
          if (p)
            DSDisposeHandle(p)
        (*arr)->dimSize = i + 1;
        /* resize the array handle to get enough space */
        err = NumericArrayResize(uPtr, 1, (UHandle*)&arr, count);
        if (err)
          return err;
        /* Fill in the data as desired */
        for (i = 0; !err && i < count; i++)
          p = (*arr)->elm[i];
    #if !complicated
          err = NumericArrayResize(uB, 1, (UHandle*)&p, 1);
    #else
          if (p)
            err = DSSetHSzClr(p, sizeof(int32));
          else
            p = DSNewHClr(sizeof(int32));
            if (p)
              (*arr)->elm[i] = p;
            else
              err = mFullErr;
    #endif
          if (!err)
            err = LStrPrintf(p, "%ld", i);
        (*arr)->dimSize = i;
        return err;
    Rolf Kalbermatter
    Message Edited by rolfk on 03-11-2009 08:40 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Resize 3D array

    This VI create a 3D array (2x2x3) from a constant in first time.
    In the second time the array is resize to obtain a line more (2x3x3).
    Why the resize function mixed the values of 2 2D arrays initials or how to add a line of 0 without destroy the initials values ?
    I use Labview 6.02Fr and I am sorry for my english!!
    Thank you very much beforehand for your answer.
    Warmly,
    Alain
    Attachments:
    resize_3D_array.vi ‏20 KB

    Had trouble opening your VI for some reason. It sounds like you should be using the Insert Into Array function.

  • Programmatically Resizing 'Decimate Array'

    I am using Labview 6i. Is it possible to programmatically resize the
    'Decimate Array' function? I've got a bunch of data to display in a graph
    and want no more than say 1000 points displayed. I want to only look at
    every other point if I have more than 1000 points and every third point if I
    have more than 2000 points, etc... Is there an easy way to accomplish this?
    Thanks,
    Peter

    You an find a vi in the palette Analyze/Signal processing/timedomain.
    This one does what you want and is called ! decimate array.vi! The function you seem to recall is called decimate 1D array.
    An easier way to find this particular one is to use FIND in the palette. Click on the magnifier glass and type dec and you find both the function and the vi.
    greetings from the Netherlands

  • How can I resize an array directly (without using reshape array)?

    Hi everyone,
    I have a porgam in which I am using an array as a command (with specific values that the user enters before running the program). By mistake, at the beginning I created a 4 dimension array (for instance), but I didn't know because I was only showing the first 3 values (not expanding the array to 4 or more). I would now like to change the size of the array from 4 to 3. I don't seem to be able to find an option (right clicking on the array) that enables me to do this directly. I don't want to use the "reshape array" icon, because this is not what I want to do. I hope I am clear enough.
    Thanks for any help,
    regards,
    Marc
    Solved!
    Go to Solution.
    Attachments:
    Forum array.vi ‏7 KB

    HI,
              If i have understood your question hope this helps you. If you want to change the size of the array right click on the array element and click Data Operations>Delete Element or if you want to do programmatically delete the particular element.
    Attachments:
    Forum%20array[1].vi ‏11 KB

  • How do I resize an array of strings in a CIN ?

    I've been using a call to NumericArrayResize() to allocate enough memory for numeric arrays, but I now have an array of strings that I need to build in a DLL/CIN and pass back to Labview. Can someone point me to a snippet that will demonstrate how to populate an array of strings with data?
    Kindest,
    Warren

    Check the follwing example. It may be what you want:
    Using a CIN to Create an Array of Strings in LabVIEW
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&AD517F5DCCAF70228625683A000A570F&cat=2F4F574886553A62862567AC004F032D
    Also, check the following example, as it provide an example on how to handle strings.
    Code Interface Node (CIN) That Converts a LabVIEW String to a C String, Modifies it, and Returns it as a LabVIEW String
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&D978409908EA760D8625683A000B6B6E&cat=2F4F574886553A62862567AC004F032D
    Regards;
    EV
    www.vartortech.com

  • Having trouble printing an array of prime numbers that has been resized

    HI, im having trouble with my printPrimeNumbers() method printing the current state of an array, I can only get it to print the original state it was in. The array is inside of a primeNumbers object. I used checkAndResize to resize that array. my printPrimeNumbers method must be void without a parameter. How could i get my PrintPrimeNumbers method to print out a resized array without modifying the parameter? Any ideas.
    Here is my PrimeNumbers class:
    * Created by IntelliJ IDEA.
    * User: Kevin
    * Date: Mar 4, 2007
    * Time: 1:53:56 AM
    * To change this template use File | Settings | File Templates.
    package primes;
    public class PrimeNumbers {
        private boolean [] sieve;
        public PrimeNumbers(int  upper) {
            initializeSieve(upper);
        public int getNthPrime (int n){
        int prime = 0;
        double num;
        if (n >= sieve.length)
            checkAndResize(n + 1);
        for (int i = 0; i < sieve.length; i++){
            if(sieve)
    prime++;
    if (prime == n)
    return i;
    if (prime < n && i == sieve.length -1)
    checkAndResize(2*sieve.length);
    return -1;
    public int getNumberPrimeNumbers(int n){
    int primes = 0;
    for (int i =0 ; i < sieve.length ; i ++){
    if (n > sieve.length){
    checkAndResize(n);
    if(sieve[i])
    primes++;
    else if (sieve[i])
    primes++;
    return primes;
    public int getSieveSize ()
    return sieve.length;
    public boolean isPrime (int n) {
    if (n > sieve.length){
    checkAndResize(n);
    //initializeSieve(n);
    return sieve[n];
    // prints out the prime numbers inside sieve
    public void printPrimeNumbers() {
    int n = 0;
    boolean first = true;
    System.out.print("[");
    for(int i = 0; i < sieve.length - 1; i++){
    n++;
    if(sieve[i] == true && n != sieve.length - 1) {
    if(first) first = false;
    else System.out.print(" ");
    System.out.print(i);
    System.out.println("]");
    // checks length of sieve with N and then resizes sieve if nessecary.
    private void checkAndResize (int n){
    if ((n + 1) >= sieve.length){
    initializeSieve(2*n);
    private void setMultiples (int k) {
    for (int i = 2*k; i < sieve.length; i += k)
    sieve [i] = false;
    private void initializeSieve (int upper){
    if ( upper < 2)
    sieve = new boolean [2];
    else
    sieve = new boolean [upper + 1];
    sieve[0] = false;
    sieve[1] = false;
    for (int i =2 ; i< sieve.length; i ++ )
    sieve[i] = true;
    int bound = (int) Math.ceil(Math.sqrt(sieve.length));
    for (int i = 2 ; i < bound ; i ++)
    if (sieve[i])
    setMultiples (i);
    private String booleanToString (boolean value)
    if (value)
    return "T";
    else
    return "F";
    public String toString (){
    StringBuffer buf = new StringBuffer("[");
    for (int i = 0; i < sieve.length -1 ; i ++)
    buf.append(booleanToString (sieve[i]) + " " );
    buf.append(booleanToString (sieve[sieve.length -1]) + "]");
    return buf.toString();
    here is the client code
            PrimeNumbers test = new PrimeNumbers(16);
            System.out.println(test);
            System.out.println("There are " + test.getNumberPrimeNumbers(16) +
                    " prime nummbers in the sieve from 1 to 15. \n");
            System.out.println("There are " + test.getNumberPrimeNumbers(26) +
                    "  prime numbers in the resized sieve from 1 to 25.");
            System.out.println("\nThe first 25 prime numbers are:");// makes sense why it doesnt work
            test.printPrimeNumbers();
            System.out.println("\nThe 13th prime number is: " + test.getNthPrime(13));
            System.out.println();
            System.out.println("The number 3001 is prime:  " + test.isPrime(3001));do you see how my methods resized it?
    here is the output:
    [F F T T F T F T F F F T F T F F F]
    There are 6 prime nummbers in the sieve from 1 to 15.
    There are 15 prime numbers in the resized sieve from 1 to 25.
    The first 25 prime numbers are:
    [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47]// this is only the first 15 elements
    The 13th prime number is: 41
    The number 3001 is prime: true
    thanks for taking your time to look at this

    What's the problem?
    You say that there are 15 prime numbers in the range 1-25. Your method printPrimeNumbers() prints the last calculated primes, and that is 15. So the program works.

  • Array resize

    Is there any way to resize an array using a method that has a "void" return type? ( Like calling the method "resize(a, 2)", where a is an array of ints which you want to have a length of 2?). Thanks for your help.
    ~Justin

    So would there be a way to extend the "life" of a
    variable, to put off garbage collecting in a method,
    so that a variable I declared and instansiated in the
    method could be used in another without returning or
    passing it?
    ~JustinYes, if the reference to an array was an instance variable, then a method could manipulate the reference. If the array contained information you needed, you would have to copy it to a new array.

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • Queue or array which is better?

    I need a array of clusters to be stored for which the length is not defined. I will update, Add new element to it.
    Array or queue can be used to store the clusters. Which one would be better to use in terms of memory usage, fast execution and other performance parameters.
    I have some other doubts also. 
    Consider an array of 8 elements. When an new element is added to the array using 'insert into array', 
    whether a new copy of 9 elements will be created? or 9th element will be linked after the 8th element (like linked lists)? or something else happens?
    If a new copy is created, what happens to old 8 elements in the memory, whether that memory will be freed or kept as such?
    The same doubt in case of queue also...
    Thanks in advance.. 
    Solved!
    Go to Solution.

    In your case, you want to use a queue. 
    An array is stored in RAM in consecutive memory locations. When increasing the size of the array, the data structure is increased in size and often entirely moved to a place where it can all fit. If you are resizing an array inside a fairly fast loop, the performance hit would be noticeable.
    A Queue is able to place individual elements in their own address chunks in RAM and is much more performance-friendly.
    - Cheers, Ed

  • I need a fast buffer which is resizable! Does anyone have an Example how to do that?

    If I use shift registers, I have to say how many elements I want.
    I could use an Array and a local variable and resize the Array all the time, but that is somehow not such a good idea.
    Can Anybody help
    Thank You

    As nobody had an answer I tried something out myself (see atached example). It is a dynamically resizable Buffer not using locals. I also used information of the example FIFO_WO_LocalVar2_6i.vi. Thanks!
    Attachments:
    buffer_rs.vi ‏24 KB

  • Scan array for row above a certain value

    Hello,
    How do I go about scanning a string array of x and y data and output the row with data above a certain value. I have attached a vi that I started working on but do not know how to output the x and y data that is above -80.
    Any help will be greatly appreciated.
    Thanks,
    hiNi.
    Solved!
    Go to Solution.
    Attachments:
    scan array.vi ‏11 KB

    Here's a version that might be better for large inputs, because it avoids constant resizing of arrays. Modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    scan arrayMOD_CA.vi ‏14 KB
    ScanArrayCA.PNG ‏8 KB

  • Getting a C variable length array

    Hello,
    I'm working on a DLL library. One of the functions should return to LabView a lot of data.
    By the moment I'm doing something like this (using 'by reference' parameters):
    int getDataFromC(int* data1, char* data2, double* data3); 
    The function returns an error code, which is used to know everything goes fine. The memory of each parameter is allocated by LabView when it calls the library function. In C, the function doesn't allocate memory, it just copy the information to the space allocated by LabView (*data1 = xxx. Then LabView uses it by reading each parameter. It works fine.
    The problem is that part of the data that comes from the DLL are arrays. These arrays are generally variable length arrays. Each array always comes with other value, which describes the length of the array. So the returned array can change its length.
    By the moment I'm assuming LabView allocates enough memory to let the C code writes all the array data. But it's not a good practice...
    For example:
    int getArrayFromC(int* len, int array[]);
    The C code writes the length value to the '*len' variable to inform LabView the size of the array, and writes the N ints to the array (assuming there is enough space allocated by LabView). 
    What's the array's length that LabView uses in this case?
    On the other hand, I'd prefer to use something like:
    int getArrayFromC(int* len, int* array[]);
    In this case I can control the length of the array. It is a array-by-reference situation. I could change the array used by LabView.
    What do you recommend? I just need to get a variable length array.
    Thanks!
    Mauricio

    LabVIEW allocates as much memory for an array as is needed.  They are always variable length, as LabVIEW dynamically resizes the array if you add to it.  However, when you call a DLL, the DLL cannot tell LabVIEW to increase the size of the array as it builds it.  So, the array needs to be large enough for the DLL to fill it up, or you could cause memory corruption/crashing.
    Depending on how your DLL has been written, you may be able to use the DLL to help you.  A lot of times, you specify the length as an input with the array, and the DLL checks to see if you have enough memory allocated.  If not, then the call generates an error, and the output of the len input is how big an array is needed.  So, you make a call with a size that typically is going to be large enough, and check for the error.  If you get the error, then you resize your LabVIEW array, and call the function again to get all the data.  Another option is to always call it with 0 elements, knowing you will get an error, then allocate the array.
    If the DLL has not been written to verify you have specified enough memory, then you need to allocate an array you believe is big enough.

Maybe you are looking for

  • *My* frank opinion of the N900

    *My* opinion of the N900 I know there are a few threads about that address this but I felt that it wouldn't be so bad to restart the conversation once in a while. I got my N900 a week and a half ago and am right in the middle of deciding between thes

  • Apple Mail on MacBook Air 10.10.3

    Mailbox behavior: when I 'renamed' a mailbox, then all of the messages I had stored under the previous name vanished; did I delete these through this action?

  • MBP 13" I7 wont start

    My mbp 13" wont start, i just did the update and did a shutdown, and now when i try to start it the only thing that show's is the apple logo, the loading circle thing and a loading bar, then after 1-2 min it just shut's down. Any answer is appreciate

  • Disk Warrior help

    hi, here's my situation. 2.5 dual with 3.5 gigs of RAM. Running Tiger. hard drive i believe is a Hitachi (whatever is the default drive) and is 160 gigs. I was editing in DVPSP 3 and it kept quiting on me. so i restarted. when i did the OS did not co

  • Importing OMF files

    Hello, I'm having trouble importing OMF files into Soundtrack Pro. Today, I exported an OMF file from FCP and want to import that file into Soundtrack Pro. But, when I launch Soundtrack Pro and go to the File (drop down) Menu, I do not get an option