- Different ways of managing vector's lifetime.
- Author
- Evgeni Semenov
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void default_create(void);
void explicit_opts_create(void);
void extended_header(void);
void cloning(void);
int main(void)
{
default_create();
explicit_opts_create();
extended_header();
cloning();
return 0;
}
void default_create(void)
{
if (!vector)
{
perror("vector_create");
abort();
}
}
void explicit_opts_create(void)
{
.element_size = sizeof(float),
.initial_cap = 100
);
assert(vector && "Buy more RAM!");
}
void extended_header(void)
{
typedef struct
{
size_t meta;
}
ext_t;
.ext_header_size = sizeof(ext_t),
.element_size = sizeof(long)
);
*header = (ext_t) {0};
}
void cloning(void)
{
}
void * vector_get_ext_header(const vector_t *const vector)
Provides a location where user can put a header for the derived class.
#define vector_create(...)
Vector constructor.
vector_t * vector_clone(const vector_t *const vector)
Duplicates a vector.
void vector_destroy(vector_t *const vector)
Deallocates vector.
vector_t * vector_create_(const vector_opts_t *const opts)
Vector contructor.
size_t element_size
Size of the underling element type.
Vector control structure type.
Public interface of the vector.