Jump to content

Memory Allocation

Aseliot

Can someone tell in a simple manner WHY you would choose to implement either best fit, worst fit, power of two or buddy memory allocation?

I understand that some of these ways of allocating can lead to more fragmentation in certain situations and that sometimes a combination of them might be the best solution.

 

But I can't really find the the situations in which it would be best to use either Best Fit, Worst Fit, Power of Two or Buddy.

Also what kind of program would have the most benefit/reason to use a buddy system? (Specific kind of task?)

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, Aseliot said:

Can someone tell in a simple manner WHY you would choose to implement either best fit, worst fit, power of two or buddy memory allocation?

I understand that some of these ways of allocating can lead to more fragmentation in certain situations and that sometimes a combination of them might be the best solution.

 

But I can't really find the the situations in which it would be best to use either Best Fit, Worst Fit, Power of Two or Buddy.

Also what kind of program would have the most benefit/reason to use a buddy system? (Specific kind of task?)

intuitively i would assume that if a program's resources are all in one continuous block of RAM, that it will give the best performance in all cases. Can't you just fix the wastage issue by using more RAM ?>

Home PC:

CPU: i7 4790s ~ Motherboard: Asus B85M-E ~ RAM: 32GB Ballistix Sport DDR3 1666 ~ GPU: Sapphire R9 390 Nitro ~ Case: Corsair Carbide Spec-03 ~ Storage: Kingston Predator 240GB   PCIE M.2 Boot, 2TB HDD, 3x 480GB SATA SSD's in RAID 0 ~ PSU:    Corsair CX600
Display(s): Asus PB287Q , Generic Samsung 1080p 22" ~ Cooling: Arctic T3 Air Cooler, All case fans replaced with Noctua NF-B9 Redux's ~ Keyboard: Logitech G810 Orion ~ Mouse: Cheap Microsoft Wired (i like it) ~ Sound: Radial Pro USB DAC into 250w Powered Speakers ~ Operating System: Windows 10 Enterprise x64
 

Work PC:

CPU: Intel Xeon E3 1275 v3 ~ Motherboard: Asrock E3C226D2I ~ RAM: 16GB DDR3 ~ GPU: GTX 460 ~ Case: Silverstone SG05 ~ Storage: 512GB SATA SSD ~ Displays: 3x1080p 24" mix and matched Dell monitors plus a 10" 1080p lilliput monitor above ~ Operating System: Windows 10 Enterprise x64

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, DnFx91 said:

intuitively i would assume that if a program's resources are all in one continuous block of RAM, that it will give the best performance in all cases. Can't you just fix the wastage issue by using more RAM ?>

Eh, I understand you can reclaim the space by joining the fragmentend space together. But it is an expensive operation.

 

But my question is not really about a solution to a problem, it's more about WHY would you use one or the other way of allocating specifically over the other and in what situation.

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, Aseliot said:

Eh, I understand you can reclaim the space by joining the fragmentend space together. But it is an expensive operation.

 

But my question is not really about a solution to a problem, it's more about WHY would you use one or the other way of allocating specifically over the other and in what situation.

sorry i think this might be a bit beyond my skillset. seems more like a question for github or reddit to be honest, i've always seen LTT forum as more exclusively hardware based with software, programming and computer science as an afterthought, and this seems to be reflected in most of the users i have spoken to. But that may be simply because i don't usually browse these kind of topics :)

 

Hopefully someone has your answer

Home PC:

CPU: i7 4790s ~ Motherboard: Asus B85M-E ~ RAM: 32GB Ballistix Sport DDR3 1666 ~ GPU: Sapphire R9 390 Nitro ~ Case: Corsair Carbide Spec-03 ~ Storage: Kingston Predator 240GB   PCIE M.2 Boot, 2TB HDD, 3x 480GB SATA SSD's in RAID 0 ~ PSU:    Corsair CX600
Display(s): Asus PB287Q , Generic Samsung 1080p 22" ~ Cooling: Arctic T3 Air Cooler, All case fans replaced with Noctua NF-B9 Redux's ~ Keyboard: Logitech G810 Orion ~ Mouse: Cheap Microsoft Wired (i like it) ~ Sound: Radial Pro USB DAC into 250w Powered Speakers ~ Operating System: Windows 10 Enterprise x64
 

Work PC:

CPU: Intel Xeon E3 1275 v3 ~ Motherboard: Asrock E3C226D2I ~ RAM: 16GB DDR3 ~ GPU: GTX 460 ~ Case: Silverstone SG05 ~ Storage: 512GB SATA SSD ~ Displays: 3x1080p 24" mix and matched Dell monitors plus a 10" 1080p lilliput monitor above ~ Operating System: Windows 10 Enterprise x64

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Aseliot said:

Eh, I understand you can reclaim the space by joining the fragmentend space together. But it is an expensive operation.

 

But my question is not really about a solution to a problem, it's more about WHY would you use one or the other way of allocating specifically over the other and in what situation.

well I covered this a little in uni but never really went into why to use one over the other.

 

@Nuluvius may have more in sight.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Like any other algorithm, it depends on what your program does and what your needs are.

 

If you need as little memory fragmentation as possible and you don't care about performance, use best fit.

If you want your applications to have plenty of room to grow because you don't want to call the memory allocation function often (because it's an expensive operation), use worst fit.

If you want a balance between the two, use buddy memory allocation.

 

Keep in mind for x86 systems, you're limited to 4KB pages of memory. Other processors may not have this limitation, but they may have others. ARM for instance suffers in performance if you make memory accesses in addresses not aligned to 16-bit addresses.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, M.Yurizaki said:

Keep in mind for x86 systems, you're limited to 4KB pages of memory. Other processors may not have this limitation, but they may have others. ARM for instance suffers in performance if you make memory accesses in addresses not aligned to 16-bit addresses.

Also relevant for x86 is that these 4KB pages are mapped from physical memory to virtual memory. A normal program only sees this virtual memory. The operating system can and does a lot of memory defragmentation already by remapping freed pages so they can be used again for something else.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×