I'm writing a ring buffer library in C and I'm trying to make it possible to have several ring buffers by making "objects" of a typedef struct. This is the struct in my .h library:

```
//ringbuffer.h

// declare variables in struct
typedef struct Ringbuffer
{
    int* buff;           // ring buffer
    int  buffSize;       // ring buffer size
    // more vars here
}ringbuffer;

```

This is how I initialize the buffer and it's size and also free the memory.

```
//ringbuffer.c

//initialize buffer
void ringbuffer_init(int buff_size, ringbuffer *a)                              
{
// allocate memory to buffer
    a->buff = malloc(buff_size * sizeof(int));  
}

// empty the buffer
void ringbuffer_empty(ringbuffer *a)
{
    free(a->buff);
}

```

To make a parallell to C++, I would like to initialize it so that I could be writing something equal to `Ringbuffer buffer1;` and `Ringbuffer buffer2` in C. Right now I solve this problem like this:

```
// example.c

#include "ringbuffer.h"
#define BUFFER_SIZE 10

int main(void)
{
    // create two ringbuffer instances by allocating memory
    ringbuffer* buff1 = malloc(sizeof(ringbuffer));
    ringbuffer* buff2 = malloc(sizeof(ringbuffer));

    // initialize the two buffers
    ringbuffer_init(BUFFER_SIZE, buff1);
    ringbuffer_init(BUFFER_SIZE, buff2);

    // use the buffers in some way here   

    free(buff1);
    free(buff2);
}

```

This means that the user of my library would have to allocate memory and also free it. This doesn't seem like a good implementation. How can I do this in a more delicate way?

The complete .h, .c and example.c files can be found on my [GitHub](https://github.com/mariugul/Ring-buffer-C).