I try to post an object with one array inside and was wondering why i do get error at a certain dimension of the array. So i went on testing how big my array may be with different contents.
Here is the script i used:
$(document).ready(function(){
/* jQuery-Code from here*/
// creating an object with on single array (at the moment
var array = [];
var obj = {};
// i <= 459941 OK when "xxxxxxxxxxxxxxxx"
// i <= 518807 OK when "xxxxxxxx"
// i <= 536364 OK when "xxxx"
// i <= 545688 OK when "xx"
// i <= 555355 OK when ""
for (var i = 0; i < 555355; i++)
{
array[i] = "";
}
obj["arr"] = array;
// Using the core $.ajax() method
$.ajax({
// The URL for the request
url: "test.php",
// The data to send (will be converted to a query string)
data: { new_name: obj},
// Whether this is a POST or GET request
type: "POST",
// The type of data we expect back
dataType : "json",
// Code to run if the request succeeds;
// the response is passed to the function
success: function( json ) {
//var result = JSON.parse(json);
var size = sizeof(json);
var i = json.arr;
var size = sizeof(i);
// do something with the array
//alert (array[0] * array[1]);
},
// Code to run if the request fails; the raw request and
// status codes are passed to the function
error: function( xhr, status, errorThrown )
{
alert( "Sorry, there was a problem!" );
},
// Code to run regardless of success or failure
complete: function( xhr, status )
{
// alert( "The request is complete!" );
}
});
});
checking my PHP (XAMPP) i came to this result:
Also post_max_size and memory_limit is set to 128 MB
Here are my results:
No. Of Elements ¡ String ¡ Bytes ¡ 128MB / Elements
----------------¡--------------------¡-------¡-----------------
459941 ¡ "xxxxxxxxxxxxxxxx" ¡ 32 ¡ 292
518807 ¡ "xxxxxxxx" ¡ 16 ¡ 259
536364 ¡ "xxxx" ¡ 8 ¡ 250
545688 ¡ "xx" ¡ 4 ¡ 246
555355 ¡ "" ¡ 0 ¡ 242
So it seems, that for one empty array-index 242 Byte are needed. When i assume "xx" to each array-index 246 Bytes are needed, and so on....
So my question is: Why so much memory is needed only for the constructor?