Skip to content

Commit

Permalink
Added hw3 skeleton code
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerhub committed Oct 6, 2015
1 parent 074e6bc commit 5402ceb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hw3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mm_test
core
25 changes: 25 additions & 0 deletions hw3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# WARNING
#
# You should NOT edit this file, to change compiler flags, defines, etc.
# The hw3 autograder will replace this Makefile with a fresh copy.
#
SRCS=mm_alloc.c mm_test.c
EXECUTABLES=mm_test

CC=gcc
CFLAGS=-g -Wall
LDFLAGS=

OBJS=$(SRCS:.c=.o)

all: $(EXECUTABLES)

$(EXECUTABLES): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@

.c.o:
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -rf $(EXECUTABLES) $(OBJS)
22 changes: 22 additions & 0 deletions hw3/mm_alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* mm_alloc.c
*
* Stub implementations of the mm_* routines.
*/

#include "mm_alloc.h"
#include <stdlib.h>

void *mm_malloc(size_t size) {
/* YOUR CODE HERE */
return NULL;
}

void *mm_realloc(void *ptr, size_t size) {
/* YOUR CODE HERE */
return NULL;
}

void mm_free(void *ptr) {
/* YOUR CODE HERE */
}
13 changes: 13 additions & 0 deletions hw3/mm_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* mm_alloc.h
*
* Exports a clone of the interface documented in "man 3 malloc".
*/

#pragma once

#include <stdlib.h>

void *mm_malloc(size_t size);
void *mm_realloc(void *ptr, size_t size);
void mm_free(void *ptr);
16 changes: 16 additions & 0 deletions hw3/mm_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* A simple test harness for memory alloction. You should augment this with your
* own tests.
*/

#include <stdio.h>
#include "mm_alloc.h"

int main(int argc, char **argv) {
int *data;
data = (int *) mm_malloc(4);
data[0] = 1;
mm_free(data);
printf("malloc() basic test passed!\n");
return 0;
}

0 comments on commit 5402ceb

Please sign in to comment.