Write_ToTheEnd() public method

public Write_ToTheEnd ( byte &data ) : int
data byte
return int
Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public byte[] Table_WriteToTheEnd(byte[] data)
        {
            long position = 0;

            lock (lock_fs)
            {
                position = _fsData.Write_ToTheEnd(ref data);
            }

            return(((ulong)position).To_8_bytes_array_BigEndian().Substring(8 - DefaultPointerLen, DefaultPointerLen));
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public byte[] Table_WriteToTheEnd(byte[] data)
        {
            
            long position = 0;

            /* Emulation of the direct write to the disk without sequential cache */

            //_fsData.Position = position = _fsData.Length;
            //_fsData.Write(data, 0, data.Length);

            //return ((ulong)position).To_8_bytes_array_BigEndian().Substring(8 - DefaultPointerLen, DefaultPointerLen);

            /**************************************************************/

           

            lock (lock_fs)
            {
                //case when incoming data bigger then buffer, we clean buffer and write data directly to the disk

                if (data.Length > _seqBufCapacity)
                {
                    FlushSequentialBuffer();

                    RIC.DataFilePosition = position = RIC.DataFileLength;
                    RIC.DataFileWrite(data, 0, data.Length, false);

                    //_fsData.Position = position = _fsData.Length;
                    //_fsData.Write(data, 0, data.Length);

                    return ((ulong)position).To_8_bytes_array_BigEndian().Substring(8 - DefaultPointerLen, DefaultPointerLen);
                }
                
                //Time to clean buffer
                if (_seqBuf.EOF + data.Length > _seqBufCapacity)
                {
                    FlushSequentialBuffer();
                }

                //Writing into buffer

                position = RIC.DataFileLength + _seqBuf.EOF;
                //position = _fsData.Length + _seqBuf.EOF;

                _seqBuf.Write_ToTheEnd(data);
                
                //eofData (ptr to the end of file before current commit) will be increased only after flush

            }
                        
            return ((ulong)position).To_8_bytes_array_BigEndian().Substring(8 - DefaultPointerLen, DefaultPointerLen);
        }
Example #3
0
        private void TestMemoryStorage()
        {
            if (memoryEngine == null)
            {
                memoryEngine = new DBreezeEngine(new DBreezeConfiguration()
                {
                     Storage = DBreezeConfiguration.eStorage.MEMORY
                });
            }

            //SortedDictionary<string, int> _d = new SortedDictionary<string, int>();

            //DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");
            //DateTime dt=new DateTime(1970,1,1);

            //for (int i = 0; i < 1000000; i++)
            //{
            //    _d.Add(dt.Ticks.ToString(), i);
            //    dt=dt.AddSeconds(7);
            //}

            //DBreeze.Diagnostic.SpeedStatistic.PrintOut("a", true);

            //DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");
            //int c1 = 0;
            //foreach (var row in _d.OrderBy(r => r.Key))
            //{
            //    c1++;
            //}
            //DBreeze.Diagnostic.SpeedStatistic.PrintOut("a", true);
            //Console.WriteLine(c1);

            //memoryEngine.Scheme.DeleteTable("t1");

            //DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");
            ////DateTime dt = new DateTime(1970, 1, 1);

            //using (var tran = memoryEngine.GetTransaction())
            //{
            //    for (int i = 0; i < 1000000; i++)
            //    {
            //  //      tran.Insert<string, int>("t1", dt.Ticks.ToString(), i);
            //    //    dt = dt.AddSeconds(7);

            //        tran.Insert<byte[], byte[]>("t1", i.To_4_bytes_array_BigEndian(), i.To_4_bytes_array_BigEndian());

            //    }

            //    //Console.WriteLine(tran.Count("t1"));
            //    tran.Commit();
            //}

            //DBreeze.Diagnostic.SpeedStatistic.PrintOut("a", true);

            //int c1 = 0;

            //DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");

            //using (var tran = memoryEngine.GetTransaction())
            //{
            //    DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");

            //    foreach (var row in tran.SelectForward<string, int>("t1"))
            //    {
            //        c1++;
            //    }

            //    DBreeze.Diagnostic.SpeedStatistic.PrintOut("a", true);
            //    Console.WriteLine(c1);
            //}

            ms = new MemoryStorage(10, 10, MemoryStorage.eMemoryExpandStartegy.FIXED_LENGTH_INCREASE);

            ms.Write_ToTheEnd(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            ms.Write_ToTheEnd(new byte[] { 1, 1, 1, 1, 1 });
            //ms.Write_ByOffset(17,new byte[] { 1, 1, 1, 1, 1 });
            //Console.WriteLine(ms.MemorySize);
            //Console.WriteLine(ms.Read(0, ms.MemorySize).ToBytesString(""));
            Console.WriteLine(ms.GetFullData().Length);
        }