You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • In Espruino's console, I made some initial memory tests.

    I set the

    to what the server delivers as JSON string. This used 137 variable elements of 2250 total.
    
    Then I set the responseObect to the JSON parsed responseText:
    

    var responseObj = JSON.parse(responseText);```
    This used another 240 variable elements of 2250 total.

    No code (except the variable references) - just the response string and response JS object use 377 variable elements of 2250, leaving 1837 for all the other things.

    A variable element is a number of bytes and is also a garbage collection entity (btw, strings are chained memory elements... so not contiguous memory bytes by definition, and therefore concatenation is quite 'simple' and effective) - Espruino has separate Web pages about implementation, performance, memory usage.

    This is from Espruino's Web IDE console:

    >process.memory();
    ={ "free": 2219, "usage": 31, "total": 2250, "history": 21,
      "stackEndAddress": 536909756, "flash_start": 134217728, "flash_binary_end": 207484, "flash_code_start": 134443008, "flash_length": 262144 }
    >var responseText='{"generatedAt":"2015-01-11T21:29:18.7728461+00:00","locationName":"Reading","crs":"RDG","platformAvailable":true,"nrccMessages":"","trainServices":[{"origin":{"locationName":"Bristol Temple Meads","crs":"BRI"},"destination":{"locationName":"London Paddington","crs":"PAD"},"std":"21:20","etd":"21:28","platform":"15","serviceID":"r9ccnXCZphVkCGddcS7usw==","subsequentCallingPoints":[{"locationName":"London Paddington","st":"22:05","et":"On time"}],"operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"Didcot Parkway","crs":"DID"},"destination":{"locationName":"London Paddington","crs":"PAD"},"std":"21:27","etd":"21:32","platform":"15","serviceID":"Gy57d\/+itMP4lsK2ot8HAQ==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"London Paddington","crs":"PAD"},"destination":{"locationName":"Didcot Parkway","crs":"DID"},"std":"21:27","etd":"On time","platform":"12","serviceID":"ew4MkXo5cIVDvxHkrFnaYw==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"London Paddington","crs":"PAD"},"destination":{"locationName":"Exeter St Davids","crs":"EXD"},"std":"21:31","etd":"On time","platform":"7","serviceID":"vil6sUouIa4aG4JGvcCtmA==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"}]}';
    ="{\"generatedAt\":\"2" ... "atorCode\":\"GW\"}]}"
    >process.memory();
    ={ "free": 2102, "usage": 148, "total": 2250, "history": 143,
      "stackEndAddress": 536909756, "flash_start": 134217728, "flash_binary_end": 207484, "flash_code_start": 134443008, "flash_length": 262144 }
    >var responseObj = JSON.parse(responseText);
    ={
      "generatedAt": "2015-01-11T21:29:18.7728461+00:00",
      "locationName": "Reading",
      "crs": "RDG",
      "platformAvailable": true,
      "nrccMessages": "",
      "trainServices": [
        {
          "origin": {
    "locationName": "Bristol Temple Meads",
    "crs": "BRI"
           },
          "destination": {
    "locationName": "London Paddington",
    "crs": "PAD"
           },
          "std": "21:20",
          "etd": "21:28",
          "platform": "15",
          "serviceID": "r9ccnXCZphVkCGddcS7usw==",
          "subsequentCallingPoints": [
    {
      "locationName": "London Paddington",
      "st": "22:05",
      "et": "On time"
     }
           ],
          "operator": "First Great Western",
          "operatorCode": "GW"
         },
        {
          "origin": {
    "locationName": "Didcot Parkway",
    "crs": "DID"
           },
          "destination": {
    "locationName": "London Paddington",
    "crs": "PAD"
           },
          "std": "21:27",
          "etd": "21:32",
          "platform": "15",
          "serviceID": "Gy57d/+itMP4lsK2ot8HAQ==",
          "subsequentCallingPoints": "",
          "operator": "First Great Western",
          "operatorCode": "GW"
         },
        {
          "origin": {
    "locationName": "London Paddington",
    "crs": "PAD"
           },
          "destination": {
    "locationName": "Didcot Parkway",
    "crs": "DID"
           },
          "std": "21:27",
          "etd": "On time",
          "platform": "12",
          "serviceID": "ew4MkXo5cIVDvxHkrFnaYw==",
          "subsequentCallingPoints": "",
          "operator": "First Great Western",
          "operatorCode": "GW"
         },
        {
          "origin": {
    "locationName": "London Paddington",
    "crs": "PAD"
           },
          "destination": {
    "locationName": "Exeter St Davids",
    "crs": "EXD"
           },
          "std": "21:31",
          "etd": "On time",
          "platform": "7",
          "serviceID": "vil6sUouIa4aG4JGvcCtmA==",
          "subsequentCallingPoints": "",
          "operator": "First Great Western",
          "operatorCode": "GW"
         }
       ]
     }
    >process.memory();
    ={ "free": 1873, "usage": 377, "total": 2250, "history": 149,
      "stackEndAddress": 536909756, "flash_start": 134217728, "flash_binary_end": 207484, "flash_code_start": 134443008, "flash_length": 262144 }
    > 
    

    1 Attachment

    • depBoardRespTxtObjMemoryInConsole.png
About

Avatar for allObjects @allObjects started