From 5f7fed94b3ff74ede85ab9189221808543c4054b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 11 Dec 2011 19:23:19 +0000 Subject: Align read buffer to page boundary if posix_memalign is available. git-svn-id: http://svn.drobilla.net/serd/trunk@240 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index d035448e..7c083dd6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _POSIX_C_SOURCE 201112L /* for posix_memalign */ + #include #include #include @@ -24,6 +26,7 @@ #include #include "serd_internal.h" +#include "serd-config.h" #define NS_XSD "http://www.w3.org/2001/XMLSchema#" #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -1530,11 +1533,15 @@ serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name) { const Cursor cur = { name, 1, 1 }; me->fd = file; - me->read_buf = (uint8_t*)malloc(READ_BUF_LEN * 2); me->read_head = 0; me->cur = cur; me->from_file = true; me->eof = false; +#ifdef HAVE_POSIX_MEMALIGN + posix_memalign((void**)&me->read_buf, 4096, READ_BUF_LEN * 2); +#else + me->read_buf = (uint8_t*)malloc(READ_BUF_LEN * 2); +#endif /* Read into the second page of the buffer. Occasionally peek_string will move the read_head to before this point when readahead causes -- cgit v1.2.1