Coder Social home page Coder Social logo

chris-gong / mymalloc Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 612 KB

CS214 Rutgers Systems Programming Assignment 1: Making a better version of malloc and free

Makefile 1.14% C 98.86%
c memory memory-management memory-hacking malloc free memory-allocation memory-leak memory-leaks

mymalloc's Introduction

My Malloc

CS214 Rutgers Systems Programming Assignment 1: Making a better version of free and malloc by simulating virtual memory.

Runs on Rutgers iLab machines (Linux x86_64 bit architecture).

To run the program, simply call the make command

make

This will produce not only an object file of mymalloc but also a memgrind executable. To excute the executable, simply call

./memgrind

Note that memgrind.c just tests the malloc and free macros defined in mymalloc. If you wish to implement our malloc and free in your program then replace all instances of memgrind in the Makefile with the name of your program. Also, make sure to include mymalloc.h in your program

#include "mymalloc.h"

Currently, our virtual memory is 5000 bytes but this can be modified by adjusting this line in mymalloc.c.

#define HEAP_SIZE 5000

Right now, the size of the meta blocks are 2 bytes each so this may limit the amount of memory that the simulated heap can hold. If the current struct cannot handle the requested HEAP_SIZE, then consider modifying our struct and bit-masking techniques that allowed us to hold both a size and in_use variable into one short in mymalloc.c

int read_in_use(meta *m) {
  return (m->info >> 15) & 1;
}

void set_in_use(meta *m) {
  m->info |= 1 << 15;
}

void clear_in_use(meta *m) {
  m->info &= ~(1 << 15);
}

unsigned short read_size(meta *m) {
  return m->info & 0x7FFF;
}

void write_size(meta *m, unsigned short new_size) {
  if (new_size > 0x7FFF) return; // TOO BIG
  m->info = (m->info & 0x8000) | (new_size & 0x7FFF);
}

and in mymalloc.h

struct _meta { 
  unsigned short info;
};

For more information on the implementation, check out the readme.pdf file. For more information on some of the test cases in memgrind.c, check out the testcases.txt file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.