Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1492 - Bunicul
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Exemplul 1 = <code>bunicul.in</code> 1300 9 7 46 100 130 180 200 300 349 450 501 607 670 750 800 802 900 902 1010 1050 30 20 50 35 60 100 100 <code>bunicul.out</code> 757 0 29 101 120 451 500 608 642 803 862 903 1002 1051 1150 === Explicație === Spațiul total liber este de <code>757</code> bytes. * Prima zonă liberă este cuprinsă între adresele <code>0 45</code>. Prima variabilă ocupă <code>30</code> bytes, spațiul alocat este intervalul <code>0,29</code>. * A doua variabilă are <code>20</code> bytes. Prima zonă liberă de dimensiunea dorită este cuprinsă în intervalul <code>101,120</code>. * Pentru a treia variabilă, care are <code>50</code> bytes, se va aloca memoria cuprinsă între <code>451,500</code>. * Pentru a patra variabilă se vor aloca <code>35</code> bytes între adresele <code>608,642</code>. * Pentru a cincea variabilă se alocă memorie în intervalul <code>803,862</code> (60 byes). * Pentru a șasea variabilă se alocă spațiul de memorie cuprins între <code>903,1002</code> (<code>100</code> bytes). * Pentru ultima variabilă se alocă spațiul de memorie de <code>100</code> bytes, cuprins între <code>1051,1150</code>. <syntaxhighlight lang="python" line="1"> def calculate_memory_allocation(M, N, occupied_intervals, R, variable_sizes): # Sort occupied intervals by starting address occupied_intervals.sort() # Calculate total available memory total_available = 0 free_intervals = [] # Find free intervals if occupied_intervals[0][0] > 0: free_intervals.append((0, occupied_intervals[0][0] - 1)) for i in range(N - 1): if occupied_intervals[i][1] + 1 < occupied_intervals[i + 1][0]: free_intervals.append((occupied_intervals[i][1] + 1, occupied_intervals[i + 1][0] - 1)) if occupied_intervals[-1][1] < M - 1: free_intervals.append((occupied_intervals[-1][1] + 1, M - 1)) for interval in free_intervals: total_available += interval[1] - interval[0] + 1 # Allocate memory for variables addresses = [] current_var_index = 0 for interval in free_intervals: start = interval[0] end = interval[1] while start <= end and current_var_index < R: var_size = variable_sizes[current_var_index] if start + var_size - 1 <= end: addresses.append((current_var_index, start)) start += var_size current_var_index += 1 else: break # If we allocated all variables if current_var_index == R: return total_available, addresses # If not all variables could be allocated max_address = addresses[-1][1] + variable_sizes[addresses[-1][0]] - 1 if addresses else -1 return total_available, len(addresses), max_address # Exemplu de utilizare: M = 1000 # Dimensiunea memoriei N = 3 # Numărul de zone ocupate occupied_intervals = [(100, 199), (300, 399), (500, 599)] # Intervalele ocupate R = 5 # Numărul de variabile declarate variable_sizes = [50, 150, 60, 80, 200] # Dimensiunea fiecărei variabile result = calculate_memory_allocation(M, N, occupied_intervals, R, variable_sizes) print(result) </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width