DOSBox-X
|
00001 /* 00002 * Copyright (C) 2018-2020 Jon Campbell 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include <string.h> 00020 #include <stdlib.h> 00021 #include "rawint.h" 00022 #include "avi_rw_iobuf.h" 00023 #include <stdlib.h> 00024 #include <unistd.h> 00025 #include <ctype.h> 00026 00027 /* common index writing code. 00028 * This code originally wrote the index one struct at a type. 00029 * If you know anything about syscall overhead and disk I/O, 00030 * that's a VERY inefficent way to do it! So index read/write 00031 * code uses our buffer to batch the index entries into RAM 00032 * and write them to disk in one burst */ 00033 unsigned char* avi_io_buf = NULL; 00034 unsigned char* avi_io_read = NULL; 00035 unsigned char* avi_io_write = NULL; 00036 unsigned char* avi_io_fence = NULL; 00037 size_t avi_io_elemsize = 0; 00038 size_t avi_io_next_adv = 0; 00039 size_t avi_io_elemcount = 0; 00040 unsigned char* avi_io_readfence = NULL; 00041 00042 unsigned char *avi_io_buffer_init(size_t structsize) { 00043 #define GROUPSIZE ((size_t)(65536*2)) 00044 if (avi_io_buf == NULL) { 00045 avi_io_buf = (unsigned char*)malloc(GROUPSIZE); 00046 if (avi_io_buf == NULL) return NULL; 00047 } 00048 00049 avi_io_elemcount = GROUPSIZE / structsize; 00050 avi_io_fence = avi_io_buf + (avi_io_elemcount * structsize); 00051 avi_io_readfence = avi_io_buf; 00052 avi_io_elemsize = structsize; 00053 avi_io_write = avi_io_buf; 00054 avi_io_read = avi_io_buf; 00055 return avi_io_buf; 00056 #undef GROUPSIZE 00057 } 00058 00059 void avi_io_buffer_free() { 00060 if (avi_io_buf) { 00061 free(avi_io_buf); 00062 avi_io_buf = NULL; 00063 } 00064 avi_io_readfence = avi_io_buf; 00065 avi_io_write = avi_io_buf; 00066 avi_io_read = avi_io_buf; 00067 } 00068