Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lindsay Knupp
csci315
Commits
2a9fade6
Commit
2a9fade6
authored
Nov 02, 2021
by
Lindsay Knupp
Browse files
end of lab
parent
f87273b9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Labs/Lab7/include/dlist.h
View file @
2a9fade6
...
...
@@ -56,6 +56,7 @@ void dlist_destroy(struct dlist *l);
*/
void
dlist_obliterate
(
struct
dlist
*
l
);
/**
* Inserts new node in dlist before the first node.
*
...
...
Labs/Lab7/src/alloc-dlist_test.c
View file @
2a9fade6
...
...
@@ -24,7 +24,7 @@
#include "dlist.h"
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
mystr
;
//
char *mystr;
struct
dlist
*
mylist
=
dlist_create
();
printf
(
"dlisttest running...
\n
"
);
...
...
Labs/Lab7/src/allocator.c
View file @
2a9fade6
...
...
@@ -43,7 +43,7 @@ void *allocate(size_t size, int alloc_type){
while
(
curr_data
->
size
<
size
){
curr_data
=
dlist_iter_next
(
free_list
);
}
ptr
=
curr_data
->
data
;
ptr
=
curr_data
->
data
;
dlist_add_back
(
allocated_list
,
curr_data
->
data
,
size
);
curr_data
->
size
=
curr_data
->
size
-
size
;
curr_data
->
data
=
curr_data
->
data
+
size
;
...
...
@@ -52,13 +52,31 @@ void *allocate(size_t size, int alloc_type){
// Best-fit policy
if
(
alloc_type
==
1
){
curr_data
=
dlist_iter_begin
(
free_list
);
size_t
diff
=
(
curr_data
->
size
)
-
size
;
size_t
min
=
curr_data
->
size
-
size
;
struct
dnode
*
smallest_block
;
while
(
curr_data
!=
NULL
){
}
//for (curr_data = dlist_iter_begin(free_list); curr_data != NULL;
// curr_data = dlist_iter_next(free_list)) {
// if ((curr_data->size > size) && ((curr_data->size - size) < min)){
// min = curr_data->size - size;
// smallest_block = curr_data;
// }
//}
//dnode_print(smallest_block);
//ptr = smallest_block->data;
//dlist_add_back(allocated_list,smallest_block->data,size);
//curr_data->size = (curr_data->size) - size;
//curr_data->data = curr_data->data + size;
}
return
ptr
;
...
...
@@ -68,12 +86,9 @@ int deallocate(void *ptr){
struct
dnode
*
removed_data
;
removed_data
=
dlist_find_remove
(
allocated_list
,
ptr
);
// dnode_print(removed_data);
dlist_add_back
(
free_list
,
removed_data
->
data
,
removed_data
->
size
);
free
(
removed_data
);
return
0
;
}
Labs/Lab7/src/dlisttest.c
View file @
2a9fade6
...
...
@@ -43,7 +43,7 @@ void traverse_backward(struct dlist *l) {
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
mystr
;
//
char *mystr;
struct
dlist
*
mylist
=
dlist_create
();
printf
(
"dlisttest running...
\n
"
);
...
...
Labs/Lab7/src/dnode.c
View file @
2a9fade6
...
...
@@ -43,6 +43,6 @@ void dnode_obliterate(struct dnode *n) {
void
dnode_print
(
struct
dnode
*
n
){
printf
(
"data = %p
\n
"
,
n
->
data
);
printf
(
"
\n
size = %zu
\n
"
,
n
->
size
);
printf
(
"size = %zu
\n
"
,
n
->
size
);
}
Labs/Lab7/src/memory-test.c
View file @
2a9fade6
...
...
@@ -25,23 +25,62 @@ int main(int argc, char *argv[]){
printf
(
"
\n
allocated-list
\n
"
);
dlist_print
(
allocated_list
);
printf
(
"
\n
------Allocating free list------
\n
"
);
void
*
ptr1
=
allocate
(
100
,
0
);
void
*
ptr2
=
allocate
(
50
,
0
);
void
*
ptr3
=
allocate
(
200
,
0
);
// printf("\n--------First Fit--------\n");
// allocate(100,0);
// void *ptr1 = allocate(50,0);
// allocate(200,0);
// printf("free-list\n");
// dlist_print(free_list);
// printf("allocated-list\n");
// dlist_print(allocated_list);
//printf("\n------Deallocating node------\n");
// deallocate(ptr1);
// printf("\nfree-list\n");
// dlist_print(free_list);
// printf("allocated-list\n");
// dlist_print(allocated_list);
printf
(
"
\n
--------Best Fit--------
\n
"
);
allocator_init
(
1024
);
allocate
(
100
,
1
);
void
*
ptr2
=
allocate
(
50
,
1
);
allocate
(
200
,
1
);
printf
(
"free-list
\n
"
);
dlist_print
(
free_list
);
printf
(
"
\n
allocated-list
\n
"
);
printf
(
"allocated-list
\n
"
);
dlist_print
(
allocated_list
);
printf
(
"
\n
------Deallocating node------
\n
"
);
//
printf("\n------Deallocating node------\n");
deallocate
(
ptr2
);
printf
(
"free-list
\n
"
);
printf
(
"
\n
free-list
\n
"
);
dlist_print
(
free_list
);
printf
(
"
\n
allocated-list
\n
"
);
printf
(
"allocated-list
\n
"
);
dlist_print
(
allocated_list
);
allocate
(
40
,
1
);
printf
(
"
\n
free-list
\n
"
);
dlist_print
(
free_list
);
printf
(
"allocated-list
\n
"
);
dlist_print
(
allocated_list
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment