Skip to content

vdevos/C-LIFO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract

A Last In First Out Linked List implementation in C.

I used this buffer for measuring runtimes in nested functions (see example) for logging.

It offers basic linked list functionality (see lifo.h) so you can easily adjust the code for other purposes.

Usage

In main.c the LIFO is used for calculating (nested) process runtimes in microseconds. The main idea is that you keep track of your process' start time and push this onto the buffer when your function ends you can pop it off again and calculate the difference: current-time - start-time

The good thing is you don't have to keep track of timestamps withing each function itself and that it also works for nested functions (as long as you push and pop consequently!)

TIP You can adjust the struct item in lifo.h for other data types.

struct item
{
    unsigned long long timestamp;
    struct item* next;
}

Compiling

Makefile

make all

Manual

gcc -g -Wall -o lifo.o -c lifo.c
gcc -g -Wall -o lifo main.c lifo.o  

Example

Basic

#include "lifo.h"

int main(int argc, char** argv)
{
    lifo_init();

    int i;
    for(i = 0; i < 10; i++) 
    {            
        push(i);
        pop();
    }

    lifo_free();
    
    return 0;
}

Advanced

See main.c.

This should give a impression of the way I used it to measure function runtimes.

About

A Last In First Out Linked List implementation in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages