| |

VerySource

 Forgot password?
 Register
Search
View: 1089|Reply: 7

Where is the block size recorded in the Release version after allocating memory to a pointer?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-2 17:40:01
| Show all posts |Read mode
Where is the release version of the allocated block management information such as the block size after allocating memory to a pointer?
    

    Recently, when I deeply analyzed the C ++ problem, I encountered a problem that could not be solved. That is, the use of heap management after C ++ program compilation is not the same as the Debug version. The Debug version is easy to understand, but how does the Release version manage it? The Debug version stores a double linked list structure in the first 32 bytes of the memory block. One member of this structure is the size of the memory block. But where is the Release version? Run the following version of the Release version of the program without knowing what it is? Which prawn can confuse me?
main ()
{
    int * pInt = new int [2];
    for (int i = 1; i <= 8; i ++)
    {
        printf ("% x\n", * (pInt-i)); // Print out the first 32 bytes of memory in Pint
    }
. . . . .
. . . . .
}
Debug version shows the result is
fdfdfdfd
33
1
8 // Memory block size
0
0
372a80 // Next block address
3729f0 // Previous block address

But the Release version is executed like this
180764
230004
0
0
abababab
abababab
baad0a00
ffffffff
The memory block size is not there at all, where will it be stored? Still do not need to record? How to collect it when released without recording?
What is in the first 32 bytes of Pint?
Reply

Use magic Report

0

Threads

37

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-2 21:51:01
| Show all posts
Don't understand
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 12:18:01
| Show all posts
Records are definitely needed, otherwise how to know the length.
Or the way is different: use tables to store?
Reply

Use magic Report

0

Threads

41

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-3 12:36:01
| Show all posts
Doesn't seem to be recorded
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-3 17:48:01
| Show all posts
The operating system records and recycles itself.In fact, the first address of each thing on the heap will record its allocated size, the ID of the application program assigned to it, and the operating system said that the landlord will go to tuition.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-5 14:48:02
| Show all posts
lklklk(Learn C ++ without getting tired)
The operating system records and recycles itself? Don't say so general, each process should record the usage of its own memory block. The operating system records which memory pages (ie blocks) the process uses! As for the operating system in the memory page, it doesn't matter.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-10 15:00:02
| Show all posts
Under VC Release, each program and each dll use _crtHeap to manage the heap. _CrtHeap is a global handle.
_crtheap = HeapCreate () initialization,
HeapAlloc (_crtheap, 0, size);
retval = HeapFree (_crtheap, 0, pBlock);
I do n’t know deeply, you can track the execution of new and delete
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-6 13:30:01
| Show all posts
What LZ is talking about is a special case. In theory, the memory applied for does not include the size for the upper layer;
Operating system internal records
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list