Ejemplo n.º 1
0
        public void Align8_long()
        {
            Aver.AreEqual(8, IntMath.Align8(3L));
            Aver.AreEqual(40, IntMath.Align8(33L));
            Aver.AreEqual(0, IntMath.Align8(0L));
            Aver.AreEqual(8, IntMath.Align8(8L));
            Aver.AreEqual(16, IntMath.Align8(16L));
            Aver.AreEqual(24, IntMath.Align8(17L));
            Aver.AreEqual(128, IntMath.Align8(127L));
            Aver.AreEqual(128, IntMath.Align8(128L));
            Aver.AreEqual(136, IntMath.Align8(129L));

            Aver.AreEqual(0, IntMath.Align8(-5L));
            Aver.AreEqual(-8, IntMath.Align8(-10L));
        }
Ejemplo n.º 2
0
        public void Align8_int()
        {
            Aver.AreEqual(8, IntMath.Align8(3));
            Aver.AreEqual(40, IntMath.Align8(33));
            Aver.AreEqual(0, IntMath.Align8(0));
            Aver.AreEqual(8, IntMath.Align8(8));
            Aver.AreEqual(16, IntMath.Align8(16));
            Aver.AreEqual(24, IntMath.Align8(17));
            Aver.AreEqual(128, IntMath.Align8(127));
            Aver.AreEqual(128, IntMath.Align8(128));
            Aver.AreEqual(136, IntMath.Align8(129));

            Aver.AreEqual(0, IntMath.Align8(-5));
            Aver.AreEqual(-8, IntMath.Align8(-10));
        }
Ejemplo n.º 3
0
                                              //must be under lock
                                              //tries to allocate the payload size in this segment ant put payload bytes in.
                                              // returns -1 when could not find spot. does not do crawl
                                              public int Allocate(byte[] payloadBuffer, int serializedSize, int allocPayloadSize, byte serVer, bool isLink)
                                              {
                                                  allocPayloadSize = IntMath.Align8(allocPayloadSize);
                                                  var allocSize = allocPayloadSize + CHUNK_HDER_SZ;

                                                  var fcs = Pile.FreeChunkSizes;

                                                  //Larger than the largest tracked free chunk
                                                  if (allocSize > fcs[fcs.Length - 1])
                                                  {
                                                      var address = scanForFreeLarge(allocPayloadSize);
                                                      if (address < 0)
                                                      {
                                                          return(-1);//no space in this segment to fit large payload
                                                      }
                                                      allocChunk(address, payloadBuffer, serializedSize, allocPayloadSize, serVer, isLink);
                                                      return(address);
                                                  }

                                                  //else try to get a chunk from size-bucketed list
                                                  for (var i = 0; i < fcs.Length; i++)
                                                  {
                                                      if (allocSize <= fcs[i])
                                                      {
                                                          var freeList = FreeChunks[i];
                                                          if (freeList.CurrentIndex >= 0)//slot found
                                                          {
                                                              var address = freeList.Addresses[freeList.CurrentIndex];
                                                              freeList.CurrentIndex--;
                                                              allocChunk(address, payloadBuffer, serializedSize, allocPayloadSize, serVer, isLink);
                                                              return(address);
                                                          } //slot found
                                                      }     //<fcs
                                                  }
                                                  return(-1);
                                              }