~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to suballoc.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *  Contents: memory allocation routines                                    *
6
6
 ****************************************************************************/
7
7
 
 
8
static const uint UNIT_SIZE=Max(sizeof(RARPPM_CONTEXT),sizeof(RARPPM_MEM_BLK));
 
9
static const uint FIXED_UNIT_SIZE=12;
 
10
 
8
11
SubAllocator::SubAllocator()
9
12
{
10
13
  Clean();
41
44
 
42
45
 
43
46
 
44
 
// Calculate RAR_MEM_BLK+Items address. Real RAR_MEM_BLK size must be
45
 
// equal to UNIT_SIZE, so we cannot just add Items to RAR_MEM_BLK address.
46
 
inline RAR_MEM_BLK* SubAllocator::MBPtr(RAR_MEM_BLK *BasePtr,int Items)
 
47
// Calculate RARPPM_MEM_BLK+Items address. Real RARPPM_MEM_BLK size must be
 
48
// equal to UNIT_SIZE, so we cannot just add Items to RARPPM_MEM_BLK address.
 
49
inline RARPPM_MEM_BLK* SubAllocator::MBPtr(RARPPM_MEM_BLK *BasePtr,int Items)
47
50
{
48
 
  return((RAR_MEM_BLK*)( ((byte *)(BasePtr))+U2B(Items) ));
 
51
  return((RARPPM_MEM_BLK*)( ((byte *)(BasePtr))+U2B(Items) ));
49
52
}
50
53
 
51
54
 
109
112
  pText=HeapStart;
110
113
 
111
114
  // Original algorithm operates with 12 byte FIXED_UNIT_SIZE, but actual
112
 
  // size of RAR_MEM_BLK and PPM_CONTEXT structures can exceed this value
 
115
  // size of RARPPM_MEM_BLK and RARPPM_CONTEXT structures can exceed this value
113
116
  // because of alignment and larger pointer fields size.
114
117
  // So we define UNIT_SIZE for this larger size and adjust memory
115
118
  // pointers accordingly.
166
169
 
167
170
inline void SubAllocator::GlueFreeBlocks()
168
171
{
169
 
  RAR_MEM_BLK s0, * p, * p1;
 
172
  RARPPM_MEM_BLK s0, * p, * p1;
170
173
  int i, k, sz;
171
174
  if (LoUnit != HiUnit)
172
175
    *LoUnit=0;
173
176
  for (i=0, s0.next=s0.prev=&s0;i < N_INDEXES;i++)
174
177
    while ( FreeList[i].next )
175
178
    {
176
 
      p=(RAR_MEM_BLK*)RemoveNode(i);
 
179
      p=(RARPPM_MEM_BLK*)RemoveNode(i);
177
180
      p->insertAt(&s0);
178
181
      p->Stamp=0xFFFF;
179
182
      p->NU=Indx2Units[i];