comparison Allocator.cpp @ 363:2bc1c8d68f41

Allocator and SpellCost Tip
author Gloval
date Fri, 22 Feb 2013 00:48:54 +0400
parents 9c0607679772
children 2dfb67633b01
comparison
equal deleted inserted replaced
359:57d81602e72c 363:2bc1c8d68f41
22 void *Allocator::AllocNamedChunk(const void *pPrevPtrValue, unsigned int uSize, const char *pName) 22 void *Allocator::AllocNamedChunk(const void *pPrevPtrValue, unsigned int uSize, const char *pName)
23 { 23 {
24 //Allocator *v4; // esi@1 24 //Allocator *v4; // esi@1
25 unsigned int v5; // eax@7 25 unsigned int v5; // eax@7
26 void *result; // eax@8 26 void *result; // eax@8
27 unsigned int *pNumBuffersUsed; // ebx@12 27 // unsigned int *pNumBuffersUsed; // ebx@12
28 unsigned int v8; // edi@15 28 unsigned int v8; // edi@15
29 char v9; // zf@15 29 char v9; // zf@15
30 int v10; // eax@16 30 int v10; // eax@16
31 void **v11; // ebx@19 31 void **v11; // ebx@19
32 void *v12; // eax@22 32 void *v12; // eax@22
33 unsigned int Size; // [sp+14h] [bp+Ch]@16 33 unsigned int Size; // [sp+14h] [bp+Ch]@16
34 34
35 int aligned_size;
36
37
38 if ( pPrevPtrValue && !aborting_app )
39 AbortWithError();
40 if ( !bBigBufferAllocated && !aborting_app )
41 AbortWithError();
42
43 if (!uSize)
44 return 0;
45
46 if (((uSize & 0x80000000u) != 0) && !aborting_app)
47 AbortWithError();
48
49 if (uNumBuffersUsed == 6000 && !aborting_app)
50 AbortWithError();
51
52 ++uNumBuffersUsed;
53
54 if (!bUseBigBuffer)
55 {
56 pMemoryBuffers[uNumBuffersUsed] = malloc(uSize);
57 if (pMemoryBuffers[uNumBuffersUsed])
58 uMemoryBuffersSizes[uNumBuffersUsed] = uSize;
59 else
60 {
61 if ( !aborting_app )
62 AbortWithError();
63 }
64 }
65 else
66 {
67
68 aligned_size =(uSize&0xFFFFFFFC) + 4;
69
70 if ((uNextFreeOffsetInBigBuffer +aligned_size) > uBigBufferSizeAligned)
71 {
72 printf("Id: %s Size: %i", pName, aligned_size);
73 CreateFileDump( "Memory");
74 if ( !aborting_app )
75 AbortWithError();
76 }
77
78 pMemoryBuffers[uNumBuffersUsed] = (char *)(pBigBufferAligned) + uNextFreeOffsetInBigBuffer;
79 uMemoryBuffersSizes[uNumBuffersUsed] =aligned_size;
80
81 if (pName)
82 strncpy(pMemoryBuffersNames[uNumBuffersUsed], pName, 11);
83 uNextFreeOffsetInBigBuffer += aligned_size;
84 }
85 return pMemoryBuffers[uNumBuffersUsed];
86
87 /*
35 //v4 = this; 88 //v4 = this;
36 if ( pPrevPtrValue && !aborting_app ) 89 if ( pPrevPtrValue && !aborting_app )
37 AbortWithError(); 90 AbortWithError();
38 if ( !bBigBufferAllocated && !aborting_app ) 91 if ( !bBigBufferAllocated && !aborting_app )
39 AbortWithError(); 92 AbortWithError();
92 } 145 }
93 else 146 else
94 { 147 {
95 result = 0; 148 result = 0;
96 } 149 }
97 return result; 150 return result;*/
98 } 151 }
99 // 720018: using guessed type int aborting_app; 152 // 720018: using guessed type int aborting_app;
100 153
101 154
102 155
111 164
112 pBigMemoryBuffer = malloc(uNumKBytes * 1024); 165 pBigMemoryBuffer = malloc(uNumKBytes * 1024);
113 if (!pBigMemoryBuffer) 166 if (!pBigMemoryBuffer)
114 return false; 167 return false;
115 168
116 pBigBufferAligned = (char *)pBigMemoryBuffer + -((unsigned __int16)pBigMemoryBuffer & 0xFFF) + 4096; 169 pBigBufferAligned = (void *)((unsigned int)(pBigMemoryBuffer) & 0xFFFF0000 + 4096);
170 //(char *)pBigMemoryBuffer + -((unsigned __int16)pBigMemoryBuffer & 0xFFF) + 4096;
117 uBigBufferSizeAligned = (uNumKBytes * 1024) - 4096; 171 uBigBufferSizeAligned = (uNumKBytes * 1024) - 4096;
118 172
119 uNumBuffersUsed = 0; 173 uNumBuffersUsed = 0;
120 uNextFreeOffsetInBigBuffer = 0; 174 uNextFreeOffsetInBigBuffer = 0;
121 175
133 unsigned int v5; // eax@13 187 unsigned int v5; // eax@13
134 signed int v6; // ecx@16 188 signed int v6; // ecx@16
135 signed int j; // edx@16 189 signed int j; // edx@16
136 char v8; // zf@20 190 char v8; // zf@20
137 191
192
193
194 unsigned int uBuffindx;
195 unsigned int indx;
196
197 if (ptr)
198 {
199 if ((!bBigBufferAllocated)&& (!aborting_app ))
200 AbortWithError();
201 for (indx = 0; indx <=uNumBuffersUsed; ++indx)
202 if (pMemoryBuffers[indx] == ptr)
203 break;
204 // if ((indx>uNumBuffersUsed)&& !aborting_app )
205 // AbortWithError(); to detect memory problems - uncomment
206 if (!bUseBigBuffer)
207 free(pMemoryBuffers[indx]);
208 pMemoryBuffers[indx] = NULL;
209 uMemoryBuffersSizes[indx] = 0;
210 pMemoryBuffersNames[indx][0] = 0;
211 if (indx == (uNumBuffersUsed-1))
212 {
213 if (indx>0)
214 {
215 uBuffindx = 0;
216 for (j = 0; j < uNumBuffersUsed-1; ++j)
217 {
218 if (pMemoryBuffers[j])
219 uBuffindx = j;
220 }
221 uNumBuffersUsed = uBuffindx + 1;
222 if (bUseBigBuffer)
223 uNextFreeOffsetInBigBuffer =
224 ((long)((char*)pMemoryBuffers[uBuffindx] -(char*)pBigBufferAligned)+ uMemoryBuffersSizes[uBuffindx]);
225 }
226 else
227 {
228 uNumBuffersUsed = 0;
229 uNextFreeOffsetInBigBuffer = 0;
230 }
231 }
232 }
233
234 /*
138 v2 = this; 235 v2 = this;
139 if ( ptr ) 236 if ( ptr )
140 { 237 {
141 if ( !this->bBigBufferAllocated && !aborting_app ) 238 if ( !this->bBigBufferAllocated && !aborting_app )
142 AbortWithError(); 239 AbortWithError();
175 { 272 {
176 v2->uNextFreeOffsetInBigBuffer = 0; 273 v2->uNextFreeOffsetInBigBuffer = 0;
177 v2->uNumBuffersUsed = 0; 274 v2->uNumBuffersUsed = 0;
178 } 275 }
179 } 276 }
180 } 277 }*/
181 } 278 }
182 // 720018: using guessed type int aborting_app; 279 // 720018: using guessed type int aborting_app;
183 280
184 281
185 282