Ahoj,
jelikoz pisu program, ktery pracuje s relativne velkym objemem pameti (ktere je rozdelena na male kousicky), napsal jsem si jednoduchy allokator (proste zavola malloc a pote prideluje zarovnane casti pameti...)
Nicmene si nejsem prilis jisty pouzitim. Je jasne, ze pokud mam nejaka surova data (strindy, struktury cisel apod.), pak je dobre je alokovat pomoci allokatoru.
Co kdyz mam ale strukturu, ktera obsahuje dalsi struktury (v cetne alokatoru) [typedef je tam kvuli konzistenci, bohuzel].
typedef struct ffcommand_part {
int max; /**< MAX value of order(sort) attribute. Default val. = 0 */
int min; /**< MIN value of order(sort) attribute. Default val. = 0 */
list_t list; /**< */
} ffcommand_part_t;
typedef struct ffcommand {
allocator_t* allocator;
ffcommand_part_t* video;
ffcommand_part_t* audio;
ffcommand_part_t* input; /**< input (with options) for ffmpeg */
ffcommand_part_t* output; /**< output (with options) */
} ffcommand_t;
void ffcommand_init(ffcommand_t* command) {
struct allocator* allocator = malloc(sizeof(allocator_t)); CHMOC(command->allocator);
allocator_init(allocator, 0);
void* _al = allocator_malloc(allocator, 4 * sizeof(ffcommand_part_t)); // ??? ??? ???
*command = (struct ffcommand) {
.allocator = allocator;
.video = (ffcommand_part_t*)_al;
.audio = (ffcommand_part_t*)(_al + 1 * sizeof(ffcommand_part_t));
.input = (ffcommand_part_t*)(_al + 2 * sizeof(ffcommand_part_t));
.output = (ffcommand_part_t*)(_al + 3 * sizeof(ffcommand_part_t));
};
ffcommand_part_init(command->video);
ffcommand_part_init(command->audio);
ffcommand_part_init(command->input);
ffcommand_part_init(command->output);
}
Pra danou strukturu alokuji alokator a pote pomoci tohoto alokatoru ziskam pamet pro struktury "audio", "video", "input", "output".
Dulezite je si uvedomit, ze alokator se pouziva hlavne pro plneni "audio", "video", ... spojaku hodnotami...
Smotny jsem vuci tomuto zpusobu rozpolcen, ale nemohu najit padne argumenty, proc takto neinicializovat strukturu, ktera obsahuje zbrusu novy alokator?
Takze se ptam - prijde vam takovato inicializace v poradku? Pokud ano/ne, proc?
Diky,
Honza