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.

Similar Messages

  • Dynamic Array resizing

    I have a class with some data members in it. Data for the objects comes frm a XML file. I have to parse out the xml file and create objects. Before reading the XML file i dunno as to how many objects i need to create. I wud like to know a way where I can dynamically increase the size of the object array as I read through the XMl file.
    Thanks in advance,
    Kris.

    This is the source:
    * @(#)ArrayList.java     1.36 01/12/03
    * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
    * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    package java.util;
    * Resizable-array implementation of the <tt>List</tt> interface.  Implements
    * all optional list operations, and permits all elements, including
    * <tt>null</tt>.  In addition to implementing the <tt>List</tt> interface,
    * this class provides methods to manipulate the size of the array that is
    * used internally to store the list.  (This class is roughly equivalent to
    * <tt>Vector</tt>, except that it is unsynchronized.)<p>
    * The <tt>size</tt>, <tt>isEmpty</tt>, <tt>get</tt>, <tt>set</tt>,
    * <tt>iterator</tt>, and <tt>listIterator</tt> operations run in constant
    * time.  The <tt>add</tt> operation runs in <i>amortized constant time</i>,
    * that is, adding n elements requires O(n) time.  All of the other operations
    * run in linear time (roughly speaking).  The constant factor is low compared
    * to that for the <tt>LinkedList</tt> implementation.<p>
    * Each <tt>ArrayList</tt> instance has a <i>capacity</i>.  The capacity is
    * the size of the array used to store the elements in the list.  It is always
    * at least as large as the list size.  As elements are added an ArrayList,
    * its capacity grows automatically.  The details of the growth policy are not
    * specified beyond the fact that adding an element has constant amortized
    * time cost.<p>
    * An application can increase the capacity of an <tt>ArrayList</tt> instance
    * before adding a large number of elements using the <tt>ensureCapacity</tt>
    * operation.  This may reduce the amount of incremental reallocation.<p>
    * <strong>Note that this implementation is not synchronized.</strong> If
    * multiple threads access an <tt>ArrayList</tt> instance concurrently, and at
    * least one of the threads modifies the list structurally, it <i>must</i> be
    * synchronized externally.  (A structural modification is any operation that
    * adds or deletes one or more elements, or explicitly resizes the backing
    * array; merely setting the value of an element is not a structural
    * modification.)  This is typically accomplished by synchronizing on some
    * object that naturally encapsulates the list.  If no such object exists, the
    * list should be "wrapped" using the <tt>Collections.synchronizedList</tt>
    * method.  This is best done at creation time, to prevent accidental
    * unsynchronized access to the list:
    * <pre>
    *     List list = Collections.synchronizedList(new ArrayList(...));
    * </pre><p>
    * The iterators returned by this class's <tt>iterator</tt> and
    * <tt>listIterator</tt> methods are <i>fail-fast</i>: if list is structurally
    * modified at any time after the iterator is created, in any way except
    * through the iterator's own remove or add methods, the iterator will throw a
    * ConcurrentModificationException.  Thus, in the face of concurrent
    * modification, the iterator fails quickly and cleanly, rather than risking
    * arbitrary, non-deterministic behavior at an undetermined time in the
    * future.
    * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
    * as it is, generally speaking, impossible to make any hard guarantees in the
    * presence of unsynchronized concurrent modification.  Fail-fast iterators
    * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
    * Therefore, it would be wrong to write a program that depended on this
    * exception for its correctness: <i>the fail-fast behavior of iterators
    * should be used only to detect bugs.</i>
    * @author  Josh Bloch
    * @version 1.36, 12/03/01
    * @see         Collection
    * @see         List
    * @see         LinkedList
    * @see         Vector
    * @see         Collections#synchronizedList(List)
    * @since   1.2
    public class ArrayList extends AbstractList
            implements List, RandomAccess, Cloneable, java.io.Serializable
        private static final long serialVersionUID = 8683452581122892189L;
         * The array buffer into which the elements of the ArrayList are stored.
         * The capacity of the ArrayList is the length of this array buffer.
        private transient Object elementData[];
         * The size of the ArrayList (the number of elements it contains).
         * @serial
        private int size;
         * Constructs an empty list with the specified initial capacity.
         * @param   initialCapacity   the initial capacity of the list.
         * @exception IllegalArgumentException if the specified initial capacity
         *            is negative
        public ArrayList(int initialCapacity) {
         super();
            if (initialCapacity < 0)
                throw new IllegalArgumentException("Illegal Capacity: "+
                                                   initialCapacity);
         this.elementData = new Object[initialCapacity];
         * Constructs an empty list with an initial capacity of ten.
        public ArrayList() {
         this(10);
         * Constructs a list containing the elements of the specified
         * collection, in the order they are returned by the collection's
         * iterator.  The <tt>ArrayList</tt> instance has an initial capacity of
         * 110% the size of the specified collection.
         * @param c the collection whose elements are to be placed into this list.
         * @throws NullPointerException if the specified collection is null.
        public ArrayList(Collection c) {
            size = c.size();
            // Allow 10% room for growth
            elementData = new Object[
                          (int)Math.min((size*110L)/100,Integer.MAX_VALUE)];
            c.toArray(elementData);
         * Trims the capacity of this <tt>ArrayList</tt> instance to be the
         * list's current size.  An application can use this operation to minimize
         * the storage of an <tt>ArrayList</tt> instance.
        public void trimToSize() {
         modCount++;
         int oldCapacity = elementData.length;
         if (size < oldCapacity) {
             Object oldData[] = elementData;
             elementData = new Object[size];
             System.arraycopy(oldData, 0, elementData, 0, size);
         * Increases the capacity of this <tt>ArrayList</tt> instance, if
         * necessary, to ensure  that it can hold at least the number of elements
         * specified by the minimum capacity argument.
         * @param   minCapacity   the desired minimum capacity.
        public void ensureCapacity(int minCapacity) {
         modCount++;
         int oldCapacity = elementData.length;
         if (minCapacity > oldCapacity) {
             Object oldData[] = elementData;
             int newCapacity = (oldCapacity * 3)/2 + 1;
                 if (newCapacity < minCapacity)
              newCapacity = minCapacity;
             elementData = new Object[newCapacity];
             System.arraycopy(oldData, 0, elementData, 0, size);
         * Returns the number of elements in this list.
         * @return  the number of elements in this list.
        public int size() {
         return size;
         * Tests if this list has no elements.
         * @return  <tt>true</tt> if this list has no elements;
         *          <tt>false</tt> otherwise.
        public boolean isEmpty() {
         return size == 0;
         * Returns <tt>true</tt> if this list contains the specified element.
         * @param elem element whose presence in this List is to be tested.
         * @return  <code>true</code> if the specified element is present;
         *          <code>false</code> otherwise.
        public boolean contains(Object elem) {
         return indexOf(elem) >= 0;
         * Searches for the first occurence of the given argument, testing
         * for equality using the <tt>equals</tt> method.
         * @param   elem   an object.
         * @return  the index of the first occurrence of the argument in this
         *          list; returns <tt>-1</tt> if the object is not found.
         * @see     Object#equals(Object)
        public int indexOf(Object elem) {
         if (elem == null) {
             for (int i = 0; i < size; i++)
              if (elementData==null)
              return i;
         } else {
         for (int i = 0; i < size; i++)
              if (elem.equals(elementData[i]))
              return i;
         return -1;
    * Returns the index of the last occurrence of the specified object in
    * this list.
    * @param elem the desired element.
    * @return the index of the last occurrence of the specified object in
    * this list; returns -1 if the object is not found.
    public int lastIndexOf(Object elem) {
         if (elem == null) {
         for (int i = size-1; i >= 0; i--)
              if (elementData[i]==null)
              return i;
         } else {
         for (int i = size-1; i >= 0; i--)
              if (elem.equals(elementData[i]))
              return i;
         return -1;
    * Returns a shallow copy of this <tt>ArrayList</tt> instance. (The
    * elements themselves are not copied.)
    * @return a clone of this <tt>ArrayList</tt> instance.
    public Object clone() {
         try {
         ArrayList v = (ArrayList)super.clone();
         v.elementData = new Object[size];
         System.arraycopy(elementData, 0, v.elementData, 0, size);
         v.modCount = 0;
         return v;
         } catch (CloneNotSupportedException e) {
         // this shouldn't happen, since we are Cloneable
         throw new InternalError();
    * Returns an array containing all of the elements in this list
    * in the correct order.
    * @return an array containing all of the elements in this list
    *      in the correct order.
    public Object[] toArray() {
         Object[] result = new Object[size];
         System.arraycopy(elementData, 0, result, 0, size);
         return result;
    * Returns an array containing all of the elements in this list in the
    * correct order; the runtime type of the returned array is that of the
    * specified array. If the list fits in the specified array, it is
    * returned therein. Otherwise, a new array is allocated with the runtime
    * type of the specified array and the size of this list.<p>
    * If the list fits in the specified array with room to spare (i.e., the
    * array has more elements than the list), the element in the array
    * immediately following the end of the collection is set to
    * <tt>null</tt>. This is useful in determining the length of the list
    * <i>only</i> if the caller knows that the list does not contain any
    * <tt>null</tt> elements.
    * @param a the array into which the elements of the list are to
    *          be stored, if it is big enough; otherwise, a new array of the
    *           same runtime type is allocated for this purpose.
    * @return an array containing the elements of the list.
    * @throws ArrayStoreException if the runtime type of a is not a supertype
    * of the runtime type of every element in this list.
    public Object[] toArray(Object a[]) {
    if (a.length < size)
    a = (Object[])java.lang.reflect.Array.newInstance(
    a.getClass().getComponentType(), size);
         System.arraycopy(elementData, 0, a, 0, size);
    if (a.length > size)
    a[size] = null;
    return a;
    // Positional Access Operations
    * Returns the element at the specified position in this list.
    * @param index index of element to return.
    * @return the element at the specified position in this list.
    * @throws IndexOutOfBoundsException if index is out of range <tt>(index
    *           < 0 || index >= size())</tt>.
    public Object get(int index) {
         RangeCheck(index);
         return elementData[index];
    * Replaces the element at the specified position in this list with
    * the specified element.
    * @param index index of element to replace.
    * @param element element to be stored at the specified position.
    * @return the element previously at the specified position.
    * @throws IndexOutOfBoundsException if index out of range
    *          <tt>(index < 0 || index >= size())</tt>.
    public Object set(int index, Object element) {
         RangeCheck(index);
         Object oldValue = elementData[index];
         elementData[index] = element;
         return oldValue;
    * Appends the specified element to the end of this list.
    * @param o element to be appended to this list.
    * @return <tt>true</tt> (as per the general contract of Collection.add).
    public boolean add(Object o) {
         ensureCapacity(size + 1); // Increments modCount!!
         elementData[size++] = o;
         return true;
    * Inserts the specified element at the specified position in this
    * list. Shifts the element currently at that position (if any) and
    * any subsequent elements to the right (adds one to their indices).
    * @param index index at which the specified element is to be inserted.
    * @param element element to be inserted.
    * @throws IndexOutOfBoundsException if index is out of range
    *          <tt>(index < 0 || index > size())</tt>.
    public void add(int index, Object element) {
         if (index > size || index < 0)
         throw new IndexOutOfBoundsException(
              "Index: "+index+", Size: "+size);
         ensureCapacity(size+1); // Increments modCount!!
         System.arraycopy(elementData, index, elementData, index + 1,
                   size - index);
         elementData[index] = element;
         size++;
    * Removes the element at the specified position in this list.
    * Shifts any subsequent elements to the left (subtracts one from their
    * indices).
    * @param index the index of the element to removed.
    * @return the element that was removed from the list.
    * @throws IndexOutOfBoundsException if index out of range <tt>(index
    *           < 0 || index >= size())</tt>.
    public Object remove(int index) {
         RangeCheck(index);
         modCount++;
         Object oldValue = elementData[index];
         int numMoved = size - index - 1;
         if (numMoved > 0)
         System.arraycopy(elementData, index+1, elementData, index,
                   numMoved);
         elementData[--size] = null; // Let gc do its work
         return oldValue;
    * Removes all of the elements from this list. The list will
    * be empty after this call returns.
    public void clear() {
         modCount++;
         // Let gc do its work
         for (int i = 0; i < size; i++)
         elementData[i] = null;
         size = 0;
    * Appends all of the elements in the specified Collection to the end of
    * this list, in the order that they are returned by the
    * specified Collection's Iterator. The behavior of this operation is
    * undefined if the specified Collection is modified while the operation
    * is in progress. (This implies that the behavior of this call is
    * undefined if the specified Collection is this list, and this
    * list is nonempty.)
    * @param c the elements to be inserted into this list.
    * @return <tt>true</tt> if this list changed as a result of the call.
    * @throws IndexOutOfBoundsException if index out of range <tt>(index
    *          < 0 || index > size())</tt>.
    * @throws NullPointerException if the specified collection is null.
    public boolean addAll(Collection c) {
         modCount++;
         int numNew = c.size();
         ensureCapacity(size + numNew);
         Iterator e = c.iterator();
         for (int i=0; i<numNew; i++)
         elementData[size++] = e.next();
         return numNew != 0;
    * Inserts all of the elements in the specified Collection into this
    * list, starting at the specified position. Shifts the element
    * currently at that position (if any) and any subsequent elements to
    * the right (increases their indices). The new elements will appear
    * in the list in the order that they are returned by the
    * specified Collection's iterator.
    * @param index index at which to insert first element
    *          from the specified collection.
    * @param c elements to be inserted into this list.
    * @return <tt>true</tt> if this list changed as a result of the call.
    * @throws IndexOutOfBoundsException if index out of range <tt>(index
    *          < 0 || index > size())</tt>.
    * @throws NullPointerException if the specified Collection is null.
    public boolean addAll(int index, Collection c) {
         if (index > size || index < 0)
         throw new IndexOutOfBoundsException(
              "Index: "+index+", Size: "+size);
         int numNew = c.size();
         ensureCapacity(size + numNew); // Increments modCount!!
         int numMoved = size - index;
         if (numMoved > 0)
         System.arraycopy(elementData, index, elementData, index + numNew,
                   numMoved);
         Iterator e = c.iterator();
         for (int i=0; i<numNew; i++)
         elementData[index++] = e.next();
         size += numNew;
         return numNew != 0;
    * Removes from this List all of the elements whose index is between
    * fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding
    * elements to the left (reduces their index).
    * This call shortens the list by <tt>(toIndex - fromIndex)</tt> elements.
    * (If <tt>toIndex==fromIndex</tt>, this operation has no effect.)
    * @param fromIndex index of first element to be removed.
    * @param toIndex index after last element to be removed.
    protected void removeRange(int fromIndex, int toIndex) {
         modCount++;
         int numMoved = size - toIndex;
    System.arraycopy(elementData, toIndex, elementData, fromIndex,
    numMoved);
         // Let gc do its work
         int newSize = size - (toIndex-fromIndex);
         while (size != newSize)
         elementData[--size] = null;
    * Check if the given index is in range. If not, throw an appropriate
    * runtime exception.
    private void RangeCheck(int index) {
         if (index >= size || index < 0)
         throw new IndexOutOfBoundsException(
              "Index: "+index+", Size: "+size);
    * Save the state of the <tt>ArrayList</tt> instance to a stream (that
    * is, serialize it).
    * @serialData The length of the array backing the <tt>ArrayList</tt>
    * instance is emitted (int), followed by all of its elements
    * (each an <tt>Object</tt>) in the proper order.
    private synchronized void writeObject(java.io.ObjectOutputStream s)
    throws java.io.IOException{
         // Write out element count, and any hidden stuff
         s.defaultWriteObject();
    // Write out array length
    s.writeInt(elementData.length);
         // Write out all elements in the proper order.
         for (int i=0; i<size; i++)
    s.writeObject(elementData[i]);
    * Reconstitute the <tt>ArrayList</tt> instance from a stream (that is,
    * deserialize it).
    private synchronized void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
         // Read in size, and any hidden stuff
         s.defaultReadObject();
    // Read in array length and allocate array
    int arrayLength = s.readInt();
    elementData = new Object[arrayLength];
         // Read in all elements in the proper order.
         for (int i=0; i<size; i++)
    elementData[i] = s.readObject();

  • [Solved] Move Software RAID 5 Array From NAS To Arch

    Edit: I probably never had a problem at all, the error in dmesg probably just scared me, because after I disconnected it I noticed that /dev/d127 was 8.1 TB, the exact size of my RAID array node in my NAS which was /dev/md0, I just overlooked it. I reconnected it to my pc and mounted /dev/md127 to /mnt/raid and got this wonderful sight!
    [bran@ra ~]$ ls /mnt/raid
    data lost+found meta sys
    [bran@ra ~]$ ls /mnt/raid/data/
    data ftproot module _NAS_Media _NAS_Piczza_ _NAS_Recycle_RAID _P2P_DownLoad_ stackable _SYS_TMP TV USBHDD
    download htdocs Movies _NAS_NFS_Exports_ NAS_Public nzbget-downloads PLEX_CONFIG sys tmp USBCopy
    I bought a Thecus N4520 a few months ago and it's ok but programs crash a lot and they're hard to debug, apps have to be updated manually and the whole thing is moderately underpowered. I'm trying to move the software RAID 5 array from the NAS to my desktop, the kernel seems to detect that there is a RAID array but all these drives aren't part of it. I'm pretty new to RAID and I'm just getting my feet wet with it.
    When I try to assemble the RAID array, it just tells me that it isn't an md array. How can I get it to build my array?
    [bran@ra ~]$ sudo mdadm --assemble /dev/sdb /dev/sdc /dev/sdd /dev/sde
    mdadm: device /dev/sdb exists but is not an md array.
    Found this little chunk of info in dmesg, it says that the md devices have unknown partition tables.
    [ 3.262225] md: raid1 personality registered for level 1
    [ 3.262483] iTCO_wdt: Intel TCO WatchDog Timer Driver v1.10
    [ 3.262508] iTCO_wdt: Found a Patsburg TCO device (Version=2, TCOBASE=0x0460)
    [ 3.262585] iTCO_wdt: initialized. heartbeat=30 sec (nowayout=0)
    [ 3.262933] md/raid1:md126: active with 4 out of 4 mirrors
    [ 3.262961] md126: detected capacity change from 0 to 536850432
    [ 3.263272] RAID1 conf printout:
    [ 3.263274] --- wd:4 rd:4
    [ 3.263276] disk 0, wo:0, o:1, dev:sdc3
    [ 3.263276] disk 1, wo:0, o:1, dev:sdb3
    [ 3.263277] disk 2, wo:0, o:1, dev:sdd3
    [ 3.263278] disk 3, wo:0, o:1, dev:sde3
    [ 3.263501] md: bind<sde4>
    [ 3.264810] md: bind<sdb2>
    [ 3.268262] async_tx: api initialized (async)
    [ 3.272632] md: raid6 personality registered for level 6
    [ 3.272636] md: raid5 personality registered for level 5
    [ 3.272637] md: raid4 personality registered for level 4
    [ 3.272905] md/raid:md127: device sdb2 operational as raid disk 1
    [ 3.272908] md/raid:md127: device sde2 operational as raid disk 3
    [ 3.272910] md/raid:md127: device sdd2 operational as raid disk 2
    [ 3.272911] md/raid:md127: device sdc2 operational as raid disk 0
    [ 3.273211] md/raid:md127: allocated 0kB
    [ 3.273241] md/raid:md127: raid level 5 active with 4 out of 4 devices, algorithm 2
    [ 3.273243] RAID conf printout:
    [ 3.273244] --- level:5 rd:4 wd:4
    [ 3.273245] disk 0, o:1, dev:sdc2
    [ 3.273246] disk 1, o:1, dev:sdb2
    [ 3.273247] disk 2, o:1, dev:sdd2
    [ 3.273248] disk 3, o:1, dev:sde2
    [ 3.273273] md127: detected capacity change from 0 to 8929230716928
    [ 3.273322] RAID conf printout:
    [ 3.273326] --- level:5 rd:4 wd:4
    [ 3.273329] disk 0, o:1, dev:sdc2
    [ 3.273331] disk 1, o:1, dev:sdb2
    [ 3.273332] disk 2, o:1, dev:sdd2
    [ 3.273360] disk 3, o:1, dev:sde2
    [ 3.283617] md126: unknown partition table
    [ 3.309239] md127: unknown partition table
    [ 3.312660] md: bind<sdb4>
    [ 3.318291] md/raid1:md124: not clean -- starting background reconstruction
    [ 3.318296] md/raid1:md124: active with 4 out of 4 mirrors
    [ 3.318333] md124: detected capacity change from 0 to 10736291840
    [ 3.318385] RAID1 conf printout:
    [ 3.318391] --- wd:4 rd:4
    [ 3.318395] disk 0, wo:0, o:1, dev:sdc4
    [ 3.318398] disk 1, wo:0, o:1, dev:sdb4
    [ 3.318402] disk 2, wo:0, o:1, dev:sdd4
    [ 3.318405] disk 3, wo:0, o:1, dev:sde4
    [ 3.319890] md124: unknown partition table
    [ 3.323462] md: bind<sde1>
    [ 3.338094] md/raid1:md125: active with 4 out of 4 mirrors
    [ 3.338225] md125: detected capacity change from 0 to 2146414592
    [ 3.338253] RAID1 conf printout:
    [ 3.338258] --- wd:4 rd:4
    [ 3.338262] disk 0, wo:0, o:1, dev:sdc1
    [ 3.338266] disk 1, wo:0, o:1, dev:sdb1
    [ 3.338268] disk 2, wo:0, o:1, dev:sdd1
    [ 3.338271] disk 3, wo:0, o:1, dev:sde1
    Here's my full dmesg
    mdadm.conf
    # The designation "partitions" will scan all partitions found in /proc/partitions
    DEVICE partitions
    ARRAY /dev/md127 metadata=1.2 name=(none):0 UUID=d1d14afc:23490940:a0f7f996:d7b87dfb
    ARRAY /dev/md126 metadata=1.2 name=(none):50 UUID=d43d5dd6:9446766e:1a7486f4:b811e16d
    ARRAY /dev/md125 metadata=1.2 name=(none):10 UUID=f502437a:d27d335a:d11578d5:6e119d58
    ARRAY /dev/md124 metadata=1.2 name=(none):70 UUID=ea980643:5c1b79e8:64f1b4cb:2462799b
    Last edited by brando56894 (2014-04-21 22:51:01)

    Sorry I numbered them to show the flow of information, this was also just a place for me to store info as I worked through it. I managed to get it to work by creating a partition that takes up the whole drive and is actually 22 GB larger than all the other drives (since I found out that the had root, swap and home partitions that are no longer needed).
    I should be able to resize the other partitions without a problem, correct? They're EXT4. Should I unmount the raid array and do them individually, remount the array, let it sync and do the next? Or just unmount the array, resize all of them, mount it and let it sync?

  • Adding A New Drive To A Software RAID 5 Array

    Edit 3: Just mounted the partitions and I can delete them because they contain nothing special. Is it safe to expand the 2nd partition of each drive to fill up the left over 22 GB?
    Edit 2: I just deleted all the partitions off of my new drive and created one partition, then added it to the array and it works just fine. My next question is, can I delete all the smaller partitions and expand /dev/sd[x]2 to reclaim all the space (about 70 GB)?
    One of my drives failed and Western Digital sent me a new drive, except it was an external drive instead of an internal drive, so I cracked it open and the label looked different. Turns out it's just refurbished and it's the same model as my other drives (WD Caviar Green 3 TB).
    I've read through the wiki article on Software RAID and created the partitions exactly the same as my other drives, but while creating the main 2.7 TB partition it says that the ending sector is out of range when it isn't. I'm new to all this so I have no idea what to do. From what I've read there normally aren't this many partitions per disk, correct? I also have md124, md125 and md126 for the other partitions. md127 is for the 2.7 TB partitions. I took the array out of my Thecus N4520. I have a 3 TB external drive and a 1TB internal, along with another 500 GB drive. Would I be better off at destroying the RAID set and creating a fresh RAID 5 set, considering I'm losing about 90 GB if I don't need the smaller partitions.
    /dev/sdc
    Disk /dev/sdc: 5860533168 sectors, 2.7 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 00636413-FB4D-408D-BC7F-EBAF880FBE6D
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 5860533134
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 43941 sectors (21.5 MiB)
    Number Start (sector) End (sector) Size Code Name
    1 41945088 46139375 2.0 GiB FD00
    2 47187968 5860491263 2.7 TiB FD00 THECUS
    3 46139392 47187951 512.0 MiB FD00
    4 2048 20973559 10.0 GiB FD00 i686-THECUS
    5 20973568 41945071 10.0 GiB FD00
    /dev/sdd
    Disk /dev/sdd: 5860533168 sectors, 2.7 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): C5900FF4-95A1-44BD-8A36-E1150E4FC458
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 5860533134
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 43941 sectors (21.5 MiB)
    Number Start (sector) End (sector) Size Code Name
    1 41945088 46139375 2.0 GiB FD00
    2 47187968 5860491263 2.7 TiB FD00 THECUS
    3 46139392 47187951 512.0 MiB FD00
    4 2048 20973559 10.0 GiB FD00 i686-THECUS
    5 20973568 41945071 10.0 GiB FD00
    /dev/sde
    Disk /dev/sde: 5860533168 sectors, 2.7 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 2B5527AC-9D53-4506-B31F-28736A0435BD
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 5860533134
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 43941 sectors (21.5 MiB)
    Number Start (sector) End (sector) Size Code Name
    1 41945088 46139375 2.0 GiB FD00
    2 47187968 5860491263 2.7 TiB FD00 THECUS
    3 46139392 47187951 512.0 MiB FD00
    4 2048 20973559 10.0 GiB FD00 i686-THECUS
    5 20973568 41945071 10.0 GiB FD00
    new drive: /dev/sdf
    Disk /dev/sdf: 5860467633 sectors, 2.7 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 93F9EF48-998D-4EF9-B5B7-936D4D3C7030
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 5860467599
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 5813281700 sectors (2.7 TiB)
    Number Start (sector) End (sector) Size Code Name
    1 41945088 46139375 2.0 GiB FD00 Linux RAID
    2 47187968 47187969 1024 bytes FD00 Linux RAID
    3 46139392 47187951 512.0 MiB FD00 Linux RAID
    4 2048 20973559 10.0 GiB FD00 Linux RAID
    5 20973568 41945071 10.0 GiB FD00 Linux RAID
    when I type in 5860491263 as the end sector gdisk does nothing, just wants more input. If I type +2.7T it accepts it, but really it just creates a partition that's 1KB in size!
    I am able to create a 2.7 TB partition with an end sector of 5860467599, this won't screw anything up will it?
    Edit 1: just tried it and got this
    [root@ra /home/bran]# mdadm --add /dev/md127 /dev/sdf2
    mdadm: /dev/sdf2 not large enough to join array
    [root@ra /home/bran]# fdisk -l /dev/sdf
    Disk /dev/sdf: 2.7 TiB, 3000559428096 bytes, 5860467633 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: 93F9EF48-998D-4EF9-B5B7-936D4D3C7030
    Device Start End Size Type
    /dev/sdf1 41945088 46139375 2G Linux RAID
    /dev/sdf2 47187968 5860467599 2.7T Linux RAID
    /dev/sdf3 46139392 47187951 512M Linux RAID
    /dev/sdf4 2048 20973559 10G Linux RAID
    /dev/sdf5 20973568 41945071 10G Linux RAID
    Last edited by brando56894 (2014-04-28 00:47:29)

    Sorry I numbered them to show the flow of information, this was also just a place for me to store info as I worked through it. I managed to get it to work by creating a partition that takes up the whole drive and is actually 22 GB larger than all the other drives (since I found out that the had root, swap and home partitions that are no longer needed).
    I should be able to resize the other partitions without a problem, correct? They're EXT4. Should I unmount the raid array and do them individually, remount the array, let it sync and do the next? Or just unmount the array, resize all of them, mount it and let it sync?

  • Need help with formatting a software RAID 5 array with xfs

    Hi,
    i'm tying to format a software RAID 5 array, using the xfs filesystem with the following command:
    # mkfs.xfs -v -m 0.5 -b 4096 -E stride=64,stripe-width=128 /dev/md0
    but all I get is the attached error message. It works fine when I use the ext4 filesystem. Any ideas?
    Thanks!
    http://i.imgur.com/cooLBwH.png
    -- mod edit: read the Forum Etiquette and only post thumbnails http://wiki.archlinux.org/index.php/For … s_and_Code [jwr] --

    Sorry I numbered them to show the flow of information, this was also just a place for me to store info as I worked through it. I managed to get it to work by creating a partition that takes up the whole drive and is actually 22 GB larger than all the other drives (since I found out that the had root, swap and home partitions that are no longer needed).
    I should be able to resize the other partitions without a problem, correct? They're EXT4. Should I unmount the raid array and do them individually, remount the array, let it sync and do the next? Or just unmount the array, resize all of them, mount it and let it sync?

  • Bug in java arrays?

    Hi, just found this in a toy program and thought it might be a bug in the way java handles arrays... I'm working on Suse 8.0 & jdk 1.4, Red Hat 7.x/8.x with jdk 1.4 and Solaris 4 jdk 1.4:
    If you have a method like this:
        public static void resize(int[] arr, int size) {
            int[] tmp = arr;
            int iterate;
            arr = new int[size];  // disassociate tmp from arr
            iterate = size > tmp.length ? tmp.length : size;
            for(int x = 0; x < iterate; x++) {
                arr[x] = tmp[x];
        }and try to call it from another class like this:
            /* could this possibly be a bug in java??? */
            Arrays.resize(state, state.length + 1);  // make array bigger
            state[state.length - 1] = start;  // store current room in arrayI get an ArrayIndexOutOfBoundsException on the call to assign start to the last index of state, which means that the new array knows its new length, but can't assign to it.
    The solution to my problem was to return arr in the resize() method and assign the returned value to state.
    This seems to go against what its supposed to happen (that the array is rezized and the pointer just updated)
    Is this a bug in java or is it te desired behaviour?
    dave.

    But when I create the 'new' array I'm assigning the
    pointer to the place where the previous array pointer
    was... This should be completely legal. Yes, it's completely legal, but it doesn't do what you want :)
    The variable in method to which you assign a new and longer array is a different one than the pointer you have in another method.
    If you just call a function to assign values to an
    array like this:> public void update(int[]arr){
    arr[0] = 2;
    } > and then use some code to look at the array you
    passed: > int[]x = {1,2,3,4};
    update(x);
    system.out.println(x[0]);> you would expect to get 2 in the
    output. Whay should this operation be different?Because in this case you wrap the reference you change (slot 0 in the array) into another object (the array). Therefore the reference you actually change is the same as the reference you expect to change.
    If you let your resize method return the new and longer array, and assign the returned value to yor old variable, you might get a better result.
    (And System.arraycopy may be more efficient than your for loop.)

  • Easier way to convert array to cluster with named variables?

    I have an array of variables, I would like to essentially unbundle that array to named variables.
    I believe the only way of doing this is by converting the array to cluster (besides removing each element one by one)?
    Is what I have done below the best way of doing it? seems a bit weird having to unbundle and rebundle by name.
    comments appreciated.
     

    Your problem code is actually right before the red square. Instead of the "array-to-cluster-unbudle dance", you should simply use a plain index array resized for the same number of outputs. same functionality, less convoluted.
    Your wiring is a bit of a mess and it is hard to tell if the order of elements in the array is the same as in the cluster.  Maybe a simple typecast to the cluster would work.
     

  • Question about array append

    Hi,
    I have a for loop and an array outside the for loop. In each iteration some values are sent to the array.
    For example, after first loop, I send following data to array:
    2 3 4 5
    4 5 6 7
    after the second loop, other data send to array again and will overwrite the former data in array. How can I append the data to the array?
    I try to use "Insert into array.vi", but how to keep the former array's data?
    Thanks.

    You have quite a few options.
    The attached VI (LabVIEW 7.1) shows two possibilities, either building the table (2D string) or building the array (2D DBL).
    (NOTES: If this is in a fast FOR loop it is not useful to update the display inside the loop, simply place the output terminals outside the FOR loop, connected to the shift registers on the right. If you know the final array size and it is relatively big, it is more efficient to initialize the shift register with the full sized array (e.g. filled with zeroes or NaNs), then replace array sections as you go in the loop. This avoids array resizing operations.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    temp_ni_MOD.vi ‏43 KB

  • Array of strings to multiple string controls

    I'm parsing a query response from a noise generator - it comes back as "1234,2345,3456,4567,5678,6789,7890,8901,9012,0123".  Basically, one long string of 10 4-digit values, comma separated, is returned.  Using the string Match attern (in a loop) I've parsed the large string into an array of 10 4-digit strings without commas.  Now, I have 10 indicators (each representing one of the 10 values) that I want this info to go into.  I could (one-by-one) stuff the array information into each of these indicators.  However, I'm wondering if there is a loop-ish approach where maybe all the indicators get grouped into a cluster and the cluster order is the iterator that indexes into the source array. 
    Any suggestions?

    Maybe you can just use a plain array indicator directly. Anything wrong with that? It reduces diagram clutter! You can always add free text labels outside as fake element labels.
    If your indicators are scattered all over the front panel, use a single "index array", resized to 10 elements.
    The attached example (LabVIEW 8.0) shows both ways.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StringParsing.vi ‏16 KB

  • Array storage

    requirement: In a labview vi and inside a while loop I want to insert a row of data, at a particular indexed location, to a fixed size and pre-existing array.
    The "Insert Into Array" would seem the obvious widget to use but labview won't let me connect the output array pin to the n-dimension array input pin.
    I've also tried creating/initialising an array outside the while loop but each time round the loop it sucks in the inital blank array, wipng the previously inserted values.
    What's the solution? Do I need to use a CIN as a work around?
    TIA

    Insert into Array resizes the array to insert a new row (or element).
    Replace Array Subset replaces a row (or element) without changing the size of the array.
    If you're working with an array within a loop, you need to use a shift register. A shift register lets you continue to modify your array within the loop, with each iteration seeing the data from the previous iteration. Without the shift register, each iteration sees the initial value passed in from outside the loop. Right-click on the border on either side of the loop and select Add Shift Register.
    See the attached LabView 6.1 example.
    Attachments:
    ReplaceRows.vi ‏36 KB

  • How do I create an n-point running average VI?

    I've been programming in sequential written languages like C for many years now. I've been using LabVIEW for the last 4 months and am having problems writing an n-point running average VI. It is really bothering me, because this would be really trivial in C or anything else. But for some reason I can't conceive how I would do this in LabVIEW. I used LabVIEW 5 for the bulk of that time, and we just upgraded to LabVIEW 8 last week so I've been learning it. Wow, some pretty big differences between the two but the gist is the same.
    I have a 5-point running average subVI written that uses a run-once while loop with shift-registers that keep their value between subsequent VI calls. This works for what I need, but have 2 problems I would like to overcome.
    1. I can't have multiple instances of the same subVI in my top-level VI program because the way the shift-registers are keeping their value between subsequent VI calls. I have to make duplicates of the .vi file (i.e., 5_point_running_average.vi, 5_point_running_average_2.vi) in order to keep all the shift registers seperate.
    2. I want it to be an n-point running average. Currently I have to jump into the VI and add another shift register to add another point. I often change my sample rate, and thus being able to have a different averaging window is really handy.
    So the VI takes 2 inputs:
    n - (integer) the number of points to computer the average over.
    in - (real) the current data point.
    output:
    out[i] = (in[i] + in[i-1] + ... + in[i-n-1])/n
    I've also thought about the possibility of needing a 3rd input that is "instance" which might help keep variables within the subVI separated and thus not needing separate duplicate files.
    In case you are wondering, I'm using a running average to make digital HUDs easy to read. The actual data that I'm recording to file will not be going through the running average function, because as you can see by the output function, there will be a phase shift in the output. At high sample rates, the digital displays can be moving very rapidly and that makes them hard to read.
    Other recommendations as to how to make digital displays easy to read to help operators while performing tests? As for instantaneous data smoothing, so to speak. I already make the displays very large if they are critical.
    I'm very interested in this n-point running average solution. I've been scratching my head over it for awhile now and am quite stumped on how to approach this in LabVIEW.
    Help is very much appreciates,
    -nickerbocker

    The atomic operations (delete/insert) MUST do the following:
    When you insert into array, all higher elements need to be moved up one slot, then the element is inserted.
    When you delete from array, the lement needs to be deleted and all higher elements moved down one slot
    Both operations involve an array resizing operation and data shuffling in memory.
    How can LabVIEW be sure that the memory can be re-used? What if your code would delete one, but insert two at each iteration? It might well be that the LabVIEW compiler properly re-uses the memory in your particular case, but there are no guarantees. A five element array is peanuts. so it would probably be difficult to notice a difference.
    You might want to run a benchmark of the different algoritms using a huge buffer.
    "First call?" is defined as followes in the online help:
    First Call? returns TRUE the first time the VI runs after the first top-level caller starts running, such as when the Run button is clicked or the Run VI method executes. If a second top-level caller calls the VI while the first top-level caller is still running, First Call? does not return TRUE a second time.
    It will only be true exactly once during the entire execution of the toplevel VI, only the first time it is called from anywhere.
    LabVIEW Champion . Do more with less code and in less time .

  • How did you learn about performance issues?

    I've been thinking about trying to get a LV certification, so I tried out the online test, and I've got a few questions about learning LV on a deeper level.
    One question asked whether it is more efficient to cast each piece of an array as its being built in a for loop, or to cast the entire array at once, after the array has been created.
    Another question asked, if array indexing is enabled on the output of a while loop then is the array resized on every iteration?
    I can make guesses at how LV works, but I really don't know what goes on under the hood. How do you pros know what's really going on with your code?
    Also for anyone out there who has been certified, can you pass the test with just experience, or do you have to undergo some NI training to learn some things? Has LV certification been beneficial to you?
    Thanks,
    John

    Hi John,
    I have mentored 2 1/2 CLA's (the 1/2 is the "Architect Supreme" and she really only needed encouragement).
    Here are my suggestions.
    1) Study for the test you plan to take. Studying above the test level you are after can only confuse things.
    2) If you can get the funding, take the NI courses suggested for that test. Some of the Q's come from the text.
    3) Monitor this Exchange for questions regarding performance and speed.
    4) Use the search box at the top of this page and search for "Greg McKaskle". Some of the best performance info available is in his writtings.
    5) Use the "info-LabVIEW" serach engine that can be found at
    http://www.searchview.net/
    and search fro Greg McKaskle and Rolf Kalbermatter. Again great information.
    6) Make a habit of using the "Task manager>>> Performance screen while you are devloping and testing. It is a good way to find out what things are good and which are bad. You find out subtle things like straight line interpolation on a chart is faster than step interpolation.
    7) Read all of the LV release notes. The questions you posted are answered in those docs and changed in LV 6.0.
    8) Review the LabVIEW ZONE challenges. They are competitions based on performance. Read the reviews.
    9) Read the white papers. Do not miss 144!
    10) Start posting Q's on this Exchange. Let us expert (myself excluded) that prowl this list help out.
    Done for now,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • I am trying to get the average of every 10 points in my table...

    I have a table of data and would like to get an output of the average every 10 points. For example, the average of points 1-10, then the average of points 11-20, then 21-30, etc.
    The challenge is that I do not know ahead of time how many points the sensor will collect each run because it depends on some external factor. I have attached a picture with some made-up data to illustrate what my table looks like. In the example I attached, the averages would be (11+34+125+77+44+232+25+213+22+89)/10 and (90+45+77+26+1+22+57+67+360+33)/10.
    My initial attempt used a case structure which found a running average and then reset whenever a multiple of 10 was reached. However, this method does not seem very efficient. Does anyone have any better ideas?
    Solved!
    Go to Solution.
    Attachments:
    sample data.JPG ‏43 KB

    JarleEkanger wrote:
    How about this? Use Delete array subset to extract chunks for averaging, and a shift register to retain the remaining array.
    It is typically not advisable to use "delete from array" in a tight loop. The constant memory reallocations due to array resizing are probably inefficient.
    Here's one simple way to do it..
    (If the number of points is not divisible by 10, the excess tail is discarded. You can easily modify that behavior if desired.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    averages of 10.png ‏5 KB
    averages of 10.vi ‏9 KB

  • What is the best way to work with a large amount of data?

    Assume you have a big text file to work that you need to store and work with, what would be the best way to do that?
    I will be adding / removing a lot of elements so I really want to stay away from array resizing overhead.
    I don't want to step on any toes here, but would binary trees / linked lists in C++ be a better solution?

    Assume you have a big text file to work that you need
    to store and work with, what would be the best way to
    do that?Parse it into a database. Then use SQL to manipulate.

  • HT1918 I am trying to enter the No. Of my VISA card (which I normaly use for payments) in the billing info of my account and it is not accepted. Does anyone have any idea why?

    I am trying to enter the No. Of my VISA card (which I normaly use for payments) in the billing info of my account and it is not accepted. Does anyone have any idea why?

    JarleEkanger wrote:
    How about this? Use Delete array subset to extract chunks for averaging, and a shift register to retain the remaining array.
    It is typically not advisable to use "delete from array" in a tight loop. The constant memory reallocations due to array resizing are probably inefficient.
    Here's one simple way to do it..
    (If the number of points is not divisible by 10, the excess tail is discarded. You can easily modify that behavior if desired.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    averages of 10.png ‏5 KB
    averages of 10.vi ‏9 KB

Maybe you are looking for