/* Mednafen - Multi-system Emulator1*2* This program is free software; you can redistribute it and/or modify3* it under the terms of the GNU General Public License as published by4* the Free Software Foundation; either version 2 of the License, or5* (at your option) any later version.6*7* This program is distributed in the hope that it will be useful,8* but WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10* GNU General Public License for more details.11*12* You should have received a copy of the GNU General Public License13* along with this program; if not, write to the Free Software14* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA15*/1617/*18Notes:19For performance reasons(like in the state rewinding code), we should try to make sure map()20returns a pointer that is aligned to at least what malloc()/realloc() provides.21(And maybe forcefully align it to at least 16 bytes in the future)22*/2324#ifndef __MDFN_MEMORYSTREAM_H25#define __MDFN_MEMORYSTREAM_H2627#include "Stream.h"2829class MemoryStream : public Stream30{31public:3233MemoryStream();34MemoryStream(uint64 alloc_hint, int alloc_hint_is_size = false); // Pass -1 instead of 1 for alloc_hint_is_size to skip initialization of the memory.35MemoryStream(Stream *stream, uint64 size_limit = ~(uint64)0);36// Will create a MemoryStream equivalent of the contents of "stream", and then "delete stream".37// Will only work if stream->tell() == 0, or if "stream" is seekable.38// stream will be deleted even if this constructor throws.39//40// Will throw an exception if the initial size() of the MemoryStream would be greater than size_limit(useful for when passing41// in GZFileStream streams).4243MemoryStream(const MemoryStream &zs);44MemoryStream & operator=(const MemoryStream &zs);4546virtual ~MemoryStream() override;4748virtual uint64 attributes(void) override;4950virtual uint8 *map(void) noexcept override;51virtual uint64 map_size(void) noexcept override;52virtual void unmap(void) noexcept override;5354virtual uint64 read(void *data, uint64 count, bool error_on_eos = true) override;55virtual void write(const void *data, uint64 count) override;56virtual void truncate(uint64 length) override;57virtual void seek(int64 offset, int whence) override;58virtual uint64 tell(void) override;59virtual uint64 size(void) override;60virtual void flush(void) override;61virtual void close(void) override;6263virtual int get_line(std::string &str) override;6465void shrink_to_fit(void) noexcept; // Minimizes alloced memory.6667private:68uint8 *data_buffer;69uint64 data_buffer_size;70uint64 data_buffer_alloced;7172uint64 position;7374void grow_if_necessary(uint64 new_required_size, uint64 hole_end);75};76#endif777879