Click here to Skip to main content
15,880,608 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
dandy7216-Dec-20 10:57
dandy7216-Dec-20 10:57 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
OriginalGriff15-Dec-20 7:29
mveOriginalGriff15-Dec-20 7:29 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
DerekT-P15-Dec-20 7:52
professionalDerekT-P15-Dec-20 7:52 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
OriginalGriff15-Dec-20 7:55
mveOriginalGriff15-Dec-20 7:55 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
Nelek15-Dec-20 22:26
protectorNelek15-Dec-20 22:26 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
Maximilien15-Dec-20 7:51
Maximilien15-Dec-20 7:51 
GeneralRe: I am seeing more use of HEIC image format on Apple Phones Pin
Shao Voon Wong15-Dec-20 16:53
mvaShao Voon Wong15-Dec-20 16:53 
GeneralI'm on fire today! Pin
honey the codewitch15-Dec-20 5:16
mvahoney the codewitch15-Dec-20 5:16 
So I am shoring up my JSON library for constrained devices. I'm testing it on a PC where I have access to a full debugger and such, but this is incredible performance, even an ancient I5 with an HDD.

Gosh I love being back to bare metal unmanaged code. This is ace! WIN WIN WIN
Output:
...
S07E06 All or Nothing
S07E07 Psychological Warfare
S07E08 Nature of the Beast
S07E09 Bitter Pill
S07E10 Things Unseen
S07E11 Tipping Point
S07E12 Sea Change
S07E13 Reckoning
Max used bytes of pool: 227
Scanned 112 episodes and 191288 characters in 5 milliseconds


5 MILLISECONDS
227 bytes of heap

I'm not counting the lexcontext space here which I have set to 1kB due to an unrelated bug I'm running down, this is just for the pooled JSON data, but when I fix the lexcontext bug I expect it will only require another 256 bytes for this query, if that.

You can give it whitelist or blacklist filters for JSON fields so you can load partial objects. I get the season_number, episode_number and name and ditch all the rest to save on average about 6k of heap (for *each* object). The whitelist filter is particularly powerful in that it can return the values for the fields already filled in to a structure for you as it filters, leading to even better performance.

C++
if (!lexContext.open("./data.json"))
{
    printf("Json file not found\r\n");
    return -1;
}
const char* fields[] = {"season_number","episode_number","name"};
// holds our returned field values:
JsonElement* values[3];
JsonParseFilter filter(fields,3,JsonParseFilter::WhiteList);
filter.pvalues=values;
size_t max = 0;
size_t episodes=0;
milliseconds start = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
// skip to each field in the document named "episodes" regardless of where
while (jsonReader.skipToField("episodes", JsonReader::All) && jsonReader.read() ) {
    // read to the value
    if(JsonReader::Array==jsonReader.nodeType() && jsonReader.read()) {
        // while we still have more array elements...
        while(JsonReader::EndArray!=jsonReader.nodeType()) {     
            // parse with a filter in place. We only want season_number,episode_number and name:
            JsonElement *pr= jsonReader.parseSubtree(pool,&filter);
            if(!pr) {
                printf("\r\nError (%d): %s\r\n\r\n",jsonReader.lastError(),jsonReader.value());
            } else {
                // since we've whitelisted, the API filled in the values for us. It's easy to retrieve them
                printf("S%02dE%02d %s\r\n",(int)filter.pvalues[0]->integer(),(int)filter.pvalues[1]->integer(),filter.pvalues[2]->string());   
                ++episodes;
            }
            if(pool.used()>max)
                max=pool.used();
            pool.freeAll();
        }
    
    }
}
milliseconds end = duration_cast<milliseconds>(system_clock::now().time_since_epoch()    );
printf("Max used bytes of pool: %d\r\nScanned %d episodes and %llu characters in %d milliseconds\r\n",(int)max,(int)episodes,lexContext.position()+1,(int)(end.count()-start.count()));
// always close the file
lexContext.close();

Real programmers use butterflies


modified 16-Dec-20 0:56am.

GeneralRe: I'm on fire today! Pin
User 1106097915-Dec-20 5:45
User 1106097915-Dec-20 5:45 
GeneralRe: I'm on fire today! Pin
honey the codewitch15-Dec-20 6:10
mvahoney the codewitch15-Dec-20 6:10 
GeneralRe: I'm on fire today! Pin
User 1106097915-Dec-20 6:26
User 1106097915-Dec-20 6:26 
GeneralRe: I'm on fire today! Pin
honey the codewitch15-Dec-20 9:10
mvahoney the codewitch15-Dec-20 9:10 
GeneralRe: I'm on fire today! Pin
Sander Rossel15-Dec-20 5:51
professionalSander Rossel15-Dec-20 5:51 
GeneralRe: I'm on fire today! Pin
honey the codewitch15-Dec-20 6:07
mvahoney the codewitch15-Dec-20 6:07 
GeneralRe: I'm on fire today! Pin
Johnny J.15-Dec-20 6:14
professionalJohnny J.15-Dec-20 6:14 
JokeRe: I'm on fire today! Pin
Daniel Pfeffer15-Dec-20 8:00
professionalDaniel Pfeffer15-Dec-20 8:00 
GeneralThought of the Day Pin
OriginalGriff15-Dec-20 4:47
mveOriginalGriff15-Dec-20 4:47 
GeneralRe: Thought of the Day Pin
W Balboos, GHB15-Dec-20 6:12
W Balboos, GHB15-Dec-20 6:12 
GeneralRe: Thought of the Day Pin
Mike Hankey15-Dec-20 8:02
mveMike Hankey15-Dec-20 8:02 
GeneralRe: Thought of the Day Pin
wwales15-Dec-20 20:41
wwales15-Dec-20 20:41 
JokeI'm a cereal killer Pin
Cp-Coder15-Dec-20 3:19
Cp-Coder15-Dec-20 3:19 
GeneralRe: I'm a cereal killer Pin
honey the codewitch15-Dec-20 3:23
mvahoney the codewitch15-Dec-20 3:23 
GeneralRe: I'm a cereal killer Pin
W Balboos, GHB15-Dec-20 6:14
W Balboos, GHB15-Dec-20 6:14 
GeneralRe: I'm a cereal killer Pin
  Forogar  15-Dec-20 3:37
professional  Forogar  15-Dec-20 3:37 
GeneralRe: I'm a cereal killer Pin
Daniel Pfeffer15-Dec-20 3:40
professionalDaniel Pfeffer15-Dec-20 3:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.