avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcrea...@apache.org
Subject svn commit: r1331813 - in /avro/trunk: CHANGES.txt lang/c/src/datafile.c
Date Sat, 28 Apr 2012 19:47:28 GMT
Author: dcreager
Date: Sat Apr 28 19:47:28 2012
New Revision: 1331813

URL: http://svn.apache.org/viewvc?rev=1331813&view=rev
Log:
AVRO-1048. C: Use less stack space in avro_file_writer_create

The avro_file_writer_create function use to allocate a 64K buffer on the
stack to render the JSON encoding of the file's schema into.  This isn't
really the best if you've got limited stack space — for instance, if
you're creating a data file from a thread or coroutine with a 64K stack.
This patch moves the scratch buffer into the avro_file_writer instance
itself; we're already allocating that from the heap, and it's easy
enough to add the 64K buffer to the end of the type.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c/src/datafile.c

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1331813&r1=1331812&r2=1331813&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Sat Apr 28 19:47:28 2012
@@ -34,6 +34,8 @@ Avro 1.7.0 (unreleased)
 
     AVRO-954. Typo in JsonCodec.cc (Nebojsa Sabovic via thiru)
 
+    AVRO-1045. C: Use less stack space in avro_file_writer_create (dcreager)
+
 Avro 1.6.3 (5 March 2012)
 
   IMPROVEMENTS

Modified: avro/trunk/lang/c/src/datafile.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=1331813&r1=1331812&r2=1331813&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Sat Apr 28 19:47:28 2012
@@ -51,6 +51,7 @@ struct avro_file_writer_t_ {
 	avro_writer_t datum_writer;
 	char* datum_buffer;
 	size_t datum_buffer_size;
+	char schema_buf[64 * 1024];
 };
 
 #define DEFAULT_BLOCK_SIZE 16 * 1024
@@ -78,7 +79,6 @@ static int write_header(avro_file_writer
 	uint8_t version = 1;
 	/* TODO: remove this static buffer */
 	avro_writer_t schema_writer;
-	char schema_buf[64 * 1024];
 	const avro_encoding_t *enc = &avro_binary_encoding;
 	int64_t schema_len;
 
@@ -92,7 +92,8 @@ static int write_header(avro_file_writer
 	check(rval, enc->write_string(w->writer, "avro.codec"));
 	check(rval, enc->write_bytes(w->writer, w->codec->name, strlen(w->codec->name)));
 	check(rval, enc->write_string(w->writer, "avro.schema"));
-	schema_writer = avro_writer_memory(schema_buf, sizeof(schema_buf));
+	schema_writer =
+	    avro_writer_memory(&w->schema_buf[0], sizeof(w->schema_buf));
 	rval = avro_schema_to_json(w->writers_schema, schema_writer);
 	if (rval) {
 		avro_writer_free(schema_writer);
@@ -101,7 +102,7 @@ static int write_header(avro_file_writer
 	schema_len = avro_writer_tell(schema_writer);
 	avro_writer_free(schema_writer);
 	check(rval,
-	      enc->write_bytes(w->writer, schema_buf, schema_len));
+	      enc->write_bytes(w->writer, w->schema_buf, schema_len));
 	check(rval, enc->write_long(w->writer, 0));
 	return write_sync(w);
 }



Mime
View raw message