public Pointer requestFreeSpace(int length)
 {
     ReadOnlyCollection<Tuple<int, int>> space = freeSpace.getList();
     List<Tuple<int, int>> space_mutable = new List<Tuple<int, int>>(space);
     space_mutable.Sort(delegate(Tuple<int, int> first, Tuple<int, int> second)
     {
         int firstLen = first.Item2 - first.Item1;
         int secondLen = second.Item2 - second.Item1;
         if (firstLen == secondLen)
         { return 0; }
         else if (firstLen > secondLen)
         { return 1; }
         else
         { return -1; }
     }); //sort smallest to largest by length
     for(int i=0; i<space_mutable.Count; i++)
     {
         int len = space_mutable[i].Item2 - space_mutable[i].Item1;
         if(len > length)
         {
             Pointer start = new Pointer(space_mutable[i].Item1, 0x08000000);
             this.markAllocated(space_mutable[i].Item1, length);
             return start;
         }
     }
     //expand ROM
     Pointer ret = new Pointer(ROMSize);
     ROMSize += length;
     return ret;
 }
 //same
 public byte[] writePointer(int offset, Pointer poin)
 {
     return owner.requestWrite(offset, poin.underlyingData);
 }
 private Pointer? getTableOffset(string iden)
 {
     List<Tuple<int, byte[]>> tables_raw = mainTable.data;
     int i;
     string current;
     for (i = 0; i < tables_raw.Count; i++)
     {
         Pointer tableOffs = new Pointer(tables_raw[i].Item2);
         current = metadataStream.ReadASCII(tableOffs.value, IDENTIFIER_LENGTH);
         if (current == iden)
             return tableOffs;
     }
     return null;
 }
 public void freePointer(Pointer poin)
 {
     owner.free(poin.underlyingData);
 }
        //private List<Metadata> myData;
        //List<MetadataTable> tables; //maybe in the works for more efficient refactoring
        public MetadataManager(string filePath)
        {
            this.metadataPath = filePath;
            if (!File.Exists(filePath))
            {
                metadataStream = File.Open(filePath, FileMode.CreateNew);
                initializeMetadata(metadataStream);
            }
            else
            { metadataStream = File.Open(filePath, FileMode.Open); }

            tables = new Dictionary<string, Metadata>();
            //myData = new List<Metadata>();

            mainTable = readMetadataTable(metadataStream, 0);//new Metadata();
            //mainTable.info = readMetadataTableInfo(metadataStream, 0);

            int numTables = mainTable.info.numEntries;
            int offs = mainTable.info.tableOffset.value;

            //int offs = 4;
            for (int i = 0; i < numTables; i++)
            {
                offs += 4; //ignore length data; constant length
                Pointer tableOffs = new Pointer(metadataStream.ReadData(offs,4)); //Get the pointer to the data table
                Metadata temp = readMetadataTable(metadataStream, tableOffs.value);
                offs += 4;
                string identifier = metadataStream.ReadASCII(tableOffs.value, IDENTIFIER_LENGTH); //read the identifier of the data table
                tables.Add(identifier, temp);
                //myData.Add(temp);
            }
            metadataStream.Close();
        }