Home
+
Products
+
Services
+
Support
 
References
 
Downloads
 
Contact Us
 
Company Profile

Synopsis

  • FileBack implements an array whose backing store is on disk.
  • Arrays based on IList may theoretically contain upto 2G elements.
  • However, long before reaching that limit, memory constraints and virtual memory page thrashing already cause performance issues.
  • By storing Serializable elements on disk, large arrays can be handled, at the cost of having to read and write files.

Usage

  • ValueTypeList
    • Use ValueTypeList to store value types such as int.
    • As int has a fixed size, the element indexed is easily addressed.
  • ReferenceEnumerator
    • Use ReferenceEnumerator to store reference types.
    • Reference types are serialized to the file store.
    • A ValueTypeList is used to store the index to the variably sized reference type.

License

  • This code is released under a BSD styled license.

Source

BaseCollection.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FileBack
{
    public class BaseCollection: IDisposable
    {
        protected FileStream m_backingStream;

        public BaseCollection()
        {
            m_backingStream = FileUtil.CreateTemporaryFileStream();
        }

        #region IDisposable Members

        private bool m_disposed = false;

        public void Dispose()
        {
            Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.m_disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    m_backingStream.Dispose();
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.

                // Note disposing has been done.
                m_disposed = true;
            }
        }

        ~BaseCollection()
        {
            Dispose(false);
        }

        #endregion
    }
}

BinaryUtil.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace FileBack
{
    class BinaryUtil
    {
        public static byte[] toByteArray<T>(T value) where T : struct
        {
            int size = Marshal.SizeOf(value);

            byte[] buffer = new byte[size];

            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            try
            {
                Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false);
            }
            finally
            {
                handle.Free();
            }

            return buffer;
        }

        public static T fromByteArray<T>(byte[] buffer) where T : struct
        {
            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            try
            {
                T value = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
                return value;
            }
            finally
            {
                handle.Free();
            }
        }
    }
}

File.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FileBack
{
    class FileUtil
    {
        public static FileStream CreateTemporaryFileStream()
        {
            FileStream tempFS;
            string path = Path.Combine(Path.GetTempPath(),Guid.NewGuid().ToString() + ".tmp");
            //Console.WriteLine("temp file " + path);
            tempFS = File.Create(path, 65536, FileOptions.DeleteOnClose);
            return tempFS;
        }
    }
}
    

ReferenceEnumerator.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileBack
{
    class ReferenceEnumerator<T> : IEnumerator<T>
    {
        ReferenceList<T> m_parent;
        T m_current;
        int m_index = -1;

        public ReferenceEnumerator(ReferenceList<T> parent)
        {
            m_parent = parent;
        }

        protected T getCurrent()
        {
            if (m_index == -1)
            {
                throw new InvalidOperationException();
            }
            else
            {
                return m_current;
            }
        }

        #region IEnumerator<T> Members

        public T Current
        {
            get {
                return getCurrent();
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get { return getCurrent(); }
        }

        public bool MoveNext()
        {
            int i = m_index + 1;

            if (i >= m_parent.Count())
            {
                return false;
            }
            else
            {
                m_index = i;
                m_current = m_parent[i];
            }

            return true;
        }

        public void Reset()
        {
            m_index = -1;
        }

        #endregion
    }
}

ReferenceList.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileBack
{
    public class ReferenceList<T> : BaseCollection, IList<T>
    {
        protected ValueTypeList<long> m_index = new ValueTypeList<long>();  // index into file for serialized object
        protected System.Runtime.Serialization.Formatters.Binary.BinaryFormatter m_serdes = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        #region IList<T> Members

        public int IndexOf(T item)
        {
            throw new NotImplementedException();
        }

        public void Insert(int index, T item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// To update a member of an object in the collection, don't do list[i].member = value.
        /// Instead, copy into p = list[i], do p.member = value, and assign list[i] = p.
        /// Then the list item will be updated.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T this[int index]
        {
            get
            {
                long offset = m_index[index];
                m_backingStream.Position = offset;
                T item = (T)m_serdes.Deserialize(m_backingStream);
                return item;
            }
            set
            {
                long offset = m_backingStream.Length;
                m_backingStream.Position = offset;
                m_serdes.Serialize(m_backingStream, value);
                m_index[index] = offset;
            }
        }

        #endregion

        #region ICollection<T> Members

        public void Add(T item)
        {
            long offset = m_backingStream.Length;
            m_backingStream.Position = offset;
            m_serdes.Serialize(m_backingStream, item);
            m_index.Add(offset);
        }

        public void Clear()
        {
            m_backingStream.SetLength(0);
            m_index.Clear();
        }

        public bool Contains(T item)
        {
            throw new NotImplementedException();
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get { return m_index.Count(); }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(T item)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return new ReferenceEnumerator<T>(this);
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return new ReferenceEnumerator<T>(this);
        }

        #endregion
    }
}

ValueTypeEnumerator.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileBack
{
    class ValueTypeEnumerator<T> : IEnumerator<T> where T : struct
    {
        ValueTypeList<T> m_parent;
        T m_current = default(T);
        int m_index = -1;

        public ValueTypeEnumerator(ValueTypeList<T> parent)
        {
            m_parent = parent;
        }

        protected T getCurrent()
        {
            if (m_index == -1)
            {
                throw new InvalidOperationException();
            }
            else
            {
                return m_current;
            }
        }

        #region IEnumerator<T> Members

        public T Current
        {
            get {
                return getCurrent();
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get {
                return getCurrent();    
            }
        }

        public bool MoveNext()
        {
            int i = m_index + 1;

            if (i >= m_parent.Count())
            {
                return false;
            }
            else
            {
                m_index = i;
                m_current = m_parent[i];
            }

            return true;
        }

        public void Reset()
        {
            m_index = -1;
        }

        #endregion
    }
}

ValueTypeList.cs

/*
 * Copyright (c) 2011 Bumble Bee Laboratories Pte Ltd. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted, provided that this copyright notice is kept
 * intact.
 *
 * BUMBLE BEE LABORATORIES PTE LTD MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BUMBLE BEE LABORATORIES PTE LTD SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  BUMBLE BEE LABORATORIES PTE LTD
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace FileBack
{
    public class ValueTypeList<T> : BaseCollection, IList<T> where T: struct
    {
        protected int m_elementSize;

        public ValueTypeList() : base()
        {
            T sample = new T();
            m_elementSize = Marshal.SizeOf(sample);
            //Console.WriteLine(sample.GetType().ToString() + "=" + m_elementSize);
        }

        protected long getFileOffset(int index)
        {
            if (index >= 0)
            {
                return (long)index * (long)m_elementSize;
            }
            else
            {
                throw new ArgumentOutOfRangeException("index out of range: " + index);
            }
        }

        #region ICollection<T> Members

        public void Add(T item)
        {
            m_backingStream.Seek(0, System.IO.SeekOrigin.End);

            byte[] buffer = BinaryUtil.toByteArray<T>(item);

            m_backingStream.Write(buffer, 0, buffer.Count());
        }

        public void Clear()
        {
            m_backingStream.SetLength(0);
        }

        public bool Contains(T item)
        {
            throw new NotImplementedException();
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get {
                long count = m_backingStream.Length;

                count = count / m_elementSize;

                if (count > int.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("the returned count is " + count + ", which would not fit in an int");
                }

                return (int) count;
            }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(T item)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return new ValueTypeEnumerator<T>(this);
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return new ValueTypeEnumerator<T>(this);
        }

        #endregion

        #region IList<T> Members

        public int IndexOf(T item)
        {
            throw new NotImplementedException();
        }

        public void Insert(int index, T item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        public T this[int index]
        {
            get
            {
                long offset = getFileOffset(index);
                m_backingStream.Seek(offset, System.IO.SeekOrigin.Begin);
                byte[] buffer = new byte[m_elementSize];
                int r = m_backingStream.Read(buffer,0,m_elementSize);
                if (r != m_elementSize)
                {
                    throw new System.IO.IOException("unable to read " + m_elementSize + " bytes from backing store");
                }
                T value = BinaryUtil.fromByteArray<T>(buffer);
                return value;
            }
            set
            {
                long offset = getFileOffset(index);
                m_backingStream.Seek(offset, System.IO.SeekOrigin.Begin);
                byte[] buffer = BinaryUtil.toByteArray<T>(value);
                m_backingStream.Write(buffer, 0, m_elementSize);
            }
        }

        #endregion
    }
}
Created on 06 Apr 2011