DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/aviwriter/avi_rw_iobuf.cpp
00001 
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include "rawint.h"
00005 #include "avi_rw_iobuf.h"
00006 #include <stdlib.h>
00007 #include <unistd.h>
00008 #include <ctype.h>
00009 
00010 /* common index writing code.
00011  * This code originally wrote the index one struct at a type.
00012  * If you know anything about syscall overhead and disk I/O,
00013  * that's a VERY inefficent way to do it! So index read/write
00014  * code uses our buffer to batch the index entries into RAM
00015  * and write them to disk in one burst */
00016 unsigned char*          avi_io_buf = NULL;
00017 unsigned char*          avi_io_read = NULL;
00018 unsigned char*          avi_io_write = NULL;
00019 unsigned char*          avi_io_fence = NULL;
00020 size_t                  avi_io_elemsize = 0;
00021 size_t                  avi_io_next_adv = 0;
00022 size_t                  avi_io_elemcount = 0;
00023 unsigned char*          avi_io_readfence = NULL;
00024 
00025 unsigned char *avi_io_buffer_init(size_t structsize) {
00026 #define GROUPSIZE ((size_t)(65536*2))
00027         if (avi_io_buf == NULL) {
00028                 avi_io_buf = (unsigned char*)malloc(GROUPSIZE);
00029                 if (avi_io_buf == NULL) return NULL;
00030         }
00031 
00032         avi_io_elemcount = GROUPSIZE / structsize;
00033         avi_io_fence = avi_io_buf + (avi_io_elemcount * structsize);
00034         avi_io_readfence = avi_io_buf;
00035         avi_io_elemsize = structsize;
00036         avi_io_write = avi_io_buf;
00037         avi_io_read = avi_io_buf;
00038         return avi_io_buf;
00039 #undef GROUPSIZE
00040 }
00041 
00042 void avi_io_buffer_free() {
00043         if (avi_io_buf) {
00044                 free(avi_io_buf);
00045                 avi_io_buf = NULL;
00046         }
00047         avi_io_readfence = avi_io_buf;
00048         avi_io_write = avi_io_buf;
00049         avi_io_read = avi_io_buf;
00050 }
00051