MCPcopy Create free account
hub / github.com/beefytech/Beef / Alloc

Method Alloc

IDEHelper/HotHeap.cpp:39–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39addr_target HotHeap::Alloc(int size)
40{
41 int blockCount = (size + BLOCK_SIZE - 1) / BLOCK_SIZE;
42
43 int triesLeft = (int)mHotAreaUsed.size();
44 while (triesLeft > 0)
45 {
46 if (mCurBlockIdx + blockCount < (int)mHotAreaUsed.size())
47 {
48 bool isOccupied = false;
49 for (int checkIdx = 0; checkIdx < blockCount; checkIdx++)
50 {
51 if ((mHotAreaUsed[mCurBlockIdx + checkIdx] & HotUseFlags_Allocated) != 0)
52 {
53 isOccupied = true;
54
55 mCurBlockIdx = mCurBlockIdx + 1;
56 triesLeft -= checkIdx + 1;
57 break;
58 }
59 }
60
61 if (!isOccupied)
62 {
63 mBlockAllocIdx += blockCount;
64 addr_target addr = mHotAreaStart + mCurBlockIdx * BLOCK_SIZE;
65
66 OutputDebugStrF("HotHeap Alloc %d length %d %@\n", mCurBlockIdx, blockCount, addr);
67
68 for (int checkIdx = 0; checkIdx < blockCount; checkIdx++)
69 {
70 mHotAreaUsed[mCurBlockIdx] = (HotUseFlags)(mHotAreaUsed[mCurBlockIdx] | HotUseFlags_Allocated);
71 mCurBlockIdx++;
72 }
73 return addr;
74 }
75 }
76 else
77 {
78 mCurBlockIdx = 0;
79 triesLeft--;
80 }
81 }
82
83 return 0;
84}
85
86void HotHeap::Release(addr_target addr, int size)
87{

Callers 3

ReadFileTOMLMethod · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected