Memory & CPU Caches

This week and last weekend I was primarily focusing on memory pools, allocators, CPU caches. I now probably know how allocators work, simply separating memory allocation & objects initialization, for example, reserve() function in std::vector, it doesn’t initialize the allocated data segment, thus permitting better performance when we don’t need initialize the data immediately.

CPU cache is another very interesting & important aspect that can (hugely) influence the performance of our programs, as it’s way faster than main memory (RAM). Smaller is faster. A great resource I found on Tuesday evening was a YouTube video – Scott Meyers’s presentation on code::drive conference 2014, a very humorous & high-quality speech!! Really awesome!

Here are a few slides screenshots, the complete presentation pdf version can be downloaded from here.

There are some interesting tops contained within it: cache lines, false sharing, data-oriented design, etc. Very practical and constructive.

From Wednesday and later, I reviewed my qsort vs std::sort problem in terms of cpu cache and cache lines. I found a hug bug (typo) in my qsort function call (embarrassed). Then I further developed that, added a few more tests (for instance, indirect sort), and drew some charts. The details can be found here.


Supplemented on Nov 24, 2020

About cache associativity: see https://www.youtube.com/watch?v=UCK-0fCchmY, a very detailed & intuitive demonstration.

Additional resource: Gallery of Processor Cache Effects by Igor Ostrovsky.

Completing in Communication

This week I had a discussion about error estimates for FEM with Miss White on Wednesday evening. While in communication about our ideas, I found a few things that I had deemed almost perfect, but it turned out that it was never meant to be perfect if you don’t have an in-depth discussion with someone of your profession yet. As well as subsequent interchange of ideas, we inspired and completed each other in the process of communication in an unconscious way.

New Project – Weekly Summary

Sooo, finally, I decided to launch a new project that aims for self-improvement via writing summaries, which can be: insightful thoughts, achievements I’ve made, things I really need to put efforts on, horrible things I’ve committed, interests I would like to nurture, awesome people I’ve encountered, challenges I should take, goals I should strive for, essential changes I must make, … Additionally, it serves an extra benefit of saving my ass from terrible writing skills, given that I’m really not into writing, or some sort of detesting feeling. Evil of laziness :)

Okay, now let’s talk about this deprived week, the week I didn’t write any code. But I did attend two classes. The one on Friday, however, got me understood something – Your mind and thinking concerning a certain discipline will rust if you don’t engage in it for a long time. For example, mathematics. It seems like I haven’t been learning mathematics for quite a long time, the agile mind of mathematics I used to have just gone – it took me an unusual amount of time to figure out some calculations that wouldn’t take a few minutes when I was a sophomore. Of course, it shouldn’t be any surprise, since that’s the mechanism our memories work, typically transient in nature. Once you regain the knowledge, it feels superb!

A Fantastic Girl

It seems that I’m invariably lucky enough to meet fantastic girls?. These days, I’ve been occasionally meeting an incredibly adorable girl in Banan Library, with a distance of about 50m to which I rented a small room for study & preparing my summer internship.

It all began with one of my library friends, a ♀, who was pissed off with me today as I didn’t grab a seat for her, though I was de facto very lucky to be one of the last two people who had the opportunity to get one.

While waiting in a long ass line for getting seats, I met another girl behind me who claimed herself to be an English tutor, humorous, agreeable. (Somehow I was & am just very interested in people (girls) who like English, who speak English, etc.) We had a nice conversation. Then when it was about to our (the last two lucky ones) turns, the girl came, in a hurry…

She was in a black casual dress, left her hair hanging loose over her shoulders, big beautiful eyes, so captivating!!

Back to yesterday evening when I was going to get a cup of water and ready for leave, thanks to my poor memory, I ran into her for the 2nd time as I was running back to fetch my filled glass left on the water filter. She recognized me and greeted me with a pure brilliant smile. Then I recalled this girl a couple of days ago when I went back to 4th floor to get my backpack, she was sitting next to my female library friend (Miss Left), and I asked her a few dumb questions. A little bit shy though, she was absolutely adorable, lovely, and agreeable to talk to. She’s AWESOME. I like her.

Then I realized it was that amazing girl, surprised & secretly pleased, I asked her a couple of dumb ass questions again, and I acquired & confirmed that she was, like me, a junior student, but majored in art. Last (also first) time she said she was majoring in art, then CS, then a poor senior high school student who was going to participate in the brute CEE in HOT July. I was so confused. Then I got all clear. Besides, I learned that she meanwhile need to learn some cs stuff, and she came to the library to review & prepare her final exams. After a short distance of observation, I found her face was suffered from acne, which might be the reason that she was a little unconfident when talking to people. Despite this, you could find her very enchanting, gorgeous, and you are definitely willing to make friends with her, for, oh my goodness, she’s merely too fantastic!

Till here, you should guess what happened next this morning… Ha, I chose to give this opportunity to that wonderful girl given that she was in more urgent need of it, plus I need to find a place where I can speak. However, I should have grabbed a seat for Miss Left as we had implicitly agreed. Sometimes it’s just hard to make a choice, and you know for sure that you would be condemned for the behavior that you thought was right, but you just have to do it, for no reason at all.

The Elevator

There’re a couple of YouTube videos that illustrate the history & principles of elevators.

History Part
Secret Life Of Machines – The Lift aka Elevator (Full Length)
View it on YouTube here
How Elevators Changed the World | Origins: The Journey of Humankind
View YouTube video here
Principle Part
How Elevator Works
View it on YouTube here

And the follow-up is a very impressive animation made by UC Berkeley.

Elevator Project Animation – UC Berkeley
View it on YouTube here
Elevator Brake Systems
Testing the limits – The Free-Fall Test
View it on YouTube here
SRH Safety device
View it on YouTube here