1

I am sending an array of float using JsonResult Object. The float array has 13M items and it represents a wav file :

public JsonResult GetWavFile()
{
     //...
     var jsonResult = Json(floatArray, JsonRequestBehavior.AllowGet);
     jsonResult.MaxJsonLength = int.MaxValue;
     return jsonResult;
}

I am getting the exception OutOfMemoryException.

This link talks only about ciruclar reference which is not my case. And when the float array is under 2M of items it works without any exception. Any ideas please how to solve this problem ? (I prefer not using chunks)

Mehdi Souregi
  • 3,153
  • 5
  • 36
  • 53
  • Don't know your requirements but wouldn't it make more sense to send it using a Stream rather than json? – Magnus May 29 '17 at 13:46
  • Try compiling as 64bit. 13M floats may fit into 32bit space but represented as json-string probably won't – Sylence May 29 '17 at 13:46
  • @Magnus I don't have any requirements, I am sending this object and I am using Ajax to read the floats and then use these floats to play the audio. – Mehdi Souregi May 29 '17 at 13:49
  • If you're not generating the data on the fly then you could just serve the file as static content. – Dirk May 29 '17 at 13:51
  • @Dirk, the file is stored as bytes (blob) on database, and I am generating the floats using a voice decoder in this function before sending these floats to the client – Mehdi Souregi May 29 '17 at 13:55
  • 1
    Json is not the way to go here. If you are getting an out of memory exception on the server imagine what will happen when the client is going to have to load this into memory. You should stream it all the way from the DB to the player on the client. – Magnus May 29 '17 at 13:59
  • any documentation for that ? Because I only know methods that streams chunks (of 30seconds), but you need to have files already splitted on database which is not my case – Mehdi Souregi May 29 '17 at 14:06

0 Answers0