55#include "debug.h"
66#include "utils.h"
77
8+ #include <sys/types.h>
9+ #include <unistd.h>
810#include <mpi.h>
911
1012size_t get_message_size () {
@@ -75,10 +77,10 @@ size_t alloc_memory(size_t size, struct leader_resources *l_r) {
7577 if (0 == b -> free ) {
7678 if (size == b -> size ) {
7779 b -> free = 1 ;
78- struct allocation * a = malloc (sizeof (struct allocation ));
80+ struct allocation * a = malloc (32 + sizeof (struct allocation ));
7981 a -> number_parts = 1 ;
8082 a -> v_address_start = b -> virtual_address ;
81- a -> parts = malloc (a -> number_parts * sizeof (struct allocation * ));
83+ a -> parts = malloc (34 + ( a -> number_parts * sizeof (struct allocation * ) ));
8284 a -> parts [0 ] = b ;
8385 add_allocation (l_r -> leader_reg , a );
8486 return b -> virtual_address ;
@@ -102,10 +104,34 @@ size_t alloc_memory(size_t size, struct leader_resources *l_r) {
102104 }
103105 }
104106 // Multi - Parts
107+ struct allocation * a = malloc (32 + sizeof (struct allocation ));
108+ a -> number_parts = 0 ;
109+ a -> parts = NULL ;
110+ a -> v_address_start = 99999999999 ;
111+ ssize_t m_size = size ;
105112 for (size_t i = 0 ; i < blks -> nb_blocks ; i ++ ) {
106-
113+ struct block * b = blks -> blks [i ];
114+ while (b && m_size > 0 ) {
115+ if (b -> free == 0 ) {
116+ b -> free = 1 ;
117+ m_size -= b -> size ;
118+ if (m_size < 0 ) {
119+ b = split_block_u (b , -1 * m_size );
120+ }
121+ if (a -> v_address_start == 99999999999 )
122+ a -> v_address_start = b -> virtual_address ;
123+ a -> number_parts ++ ;
124+ a -> parts = realloc (a -> parts , 34 + (a -> number_parts * sizeof (struct allocation * )));
125+ a -> parts [a -> number_parts - 1 ] = b ;
126+ }
127+ b = b -> next ;
128+ }
129+ if (m_size <= 0 ) {
130+ add_allocation (l_r -> leader_reg , a );
131+ return a -> v_address_start ;
132+ }
107133 }
108- return 999999999 ;
134+ return 99999999999 ;
109135}
110136
111137struct address_search * search_at_address (size_t address , struct leader_resources * l_r ) {
0 commit comments