A short, straightforward introduction to modern processor microarchitecture design.
Today’s robots are very primitive, capable of understanding only a few simple instructions such as ‘go left’, ‘go right’ and ‘build car’.
John Thomas Sladek
Warning 1: This article is intended to be about serious science in informal and witty terms.
Warning 2: Long article! Estimated reading time is 36 minutes.
This article introduces some concepts about processor microarchitecture to junior computer science students and readers interested in modern processor architecture.
A va_list error case
I recently helped someone troubleshoot a bug and saw an interesting case. The following program will have Segmentation Fault, can you see the problem?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <stdarg.h> struct Context { char *error_; }; void report_error(struct Context *ctx, const char *format, va_list args) { int len = vsnprintf(NULL, 0, format, args); // XX free(ctx->error_); ctx->error_ = (char *)malloc(len + 1); if (ctx->error_) { vsnprintf(ctx->error_, len + 1, format, args); // XX } } va_list Introduction Variadic functions in C are implemented as va_list, va_start, va_arg and va_end defined by <stdarg.
In-depth understanding of the Gradle Tooling API
1. Introduction A build system is an automated tool for generating target products from source code, including libraries, executables, generated scripts, etc. Build systems generally provide platform-related executables that can be triggered externally by executing commands, such as GUN Make, Ant, CMake, Gradle, etc. Gradle is a flexible and powerful open source Gradle is a flexible and powerful open source build system that provides cross-platform executables for external execution of Gradle builds via commands in a command line window, such as .
Google Research: Linux does a better job than Apple, Google and Microsoft at patching vulnerabilities
research from Google’s security research team, Project Zero, shows that Linux developers are more effective at fixing security vulnerabilities more quickly than anyone else (including Google).
From 2019 to 2021, Project Zero reported a total of 376 issues to vendors within the standard 90-day period.]351 (93.4%) of these bugs have been fixed, 14 (3.7%) have been flagged by the vendor as WontFix, and 11 (2.9%) remain unfixed. At the time of the bulletin, 8 had sometimes passed their fix deadlines; the remaining 3 were still within their fix deadlines.
Analyzing Nginx logs with Filebeat and Elasticsearch
This article documents the use of Filebeat, Kibana, and Elasticsearch to build a system for collecting and analyzing Nginx logs; Filebeat is responsible for delivering Nginx log data as a data source to Elasticsearch. As an introduction, we will first explain the relationship between the software: Elasticsearch is a distributed full-text search and data analysis engine based on RESTful style; Kibana is a web system for visualizing Elasticsearch data; and
IOS NSURLProtocol Explained and Pitfalls of Use
If you want to intervene in network requests, a good choice is to use NSURLProtocol, a feature of the iOS URL Loading System that provides a convenient interface to allow developers to redefine the behavior of network requests, including modifying the request initiation and response actions. In iOS web development, if there is a need for something like. adding specific header or parameters to global requests. request redirection, MOCK request
IOS Method Swizzling Usage Pitfalls
While reading the source code of a team project, I found some flaws in the way Method Swizzling is written. This article is about what the correct way to write iOS Method Swizzling should look like. Here is an implementation of iOS Method Swizzling. 1 2 3 4 5 6 7 8 9 10 11 + (void)load { Class class = [self class]; SEL fromSelector = @selector(func); SEL toSelector =
How to build your own react hooks
With the new API for hooks added in React v16.8.0, it’s important to understand how to use it and be able to write a few custom hooks for our business. 1. One of the commonly used hooks There are several built-in hooks officially provided, let’s have a brief look at their usage. 1.1 useState: State hooks If we need to update the state of the page, we can put it
Multiprocessing and daemons in nodejs
node is single-threaded, how can our node project utilize the resources of a multi-core CPU while improving the stability of the node service? This article is divided into 4 main parts to explain. node’s single thread node multi-process creation multi-process communication multi-process maintenance 1. single thread of node A process is a dynamic execution of a program with certain independent functions on a dataset, an independent unit of resource allocation
Hash and history routing in the browser
When we use front-end rendering like Vue or React, there are usually two types of routing: hash routing and history routing. hash routing: listen to the hash changes in the url and render different content, this kind of routing does not send requests to the server and does not need server-side support. history routing: listens for changes in the path in the url and requires the support of both the
The EventLoop mechanism in Js
We know that js is single-threaded, so how does js handle asynchronous code? For example, the following code is how the output is performed. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 console.log(1); setTimeout(function() { console.log(2); }, 0); new Promise(function(resolve) { console.log(3); resolve(Date.now()); }).then(function() { console.log(4); }); console.log(5); setTimeout(function() { new Promise(function(resolve) { console.log(6); resolve(Date.now()); }).then(function() { console.log(7); });
Exceptions and errors that cannot be caught by try-catch statements in js
During development, our goal is 0error, 0warning. But there are many factors beyond our control, and to avoid errors in one piece of code that affect other modules or the overall code, we often use the try-catch module to actively catch some exceptions or errors. For example, if we get the parameters in the url and parse them in JSON, we need to wrap them in try-catch because we can’t
Some tips to help you in react development
I have been using react development for 1 year, so I can’t say I am very proficient, but in the process of using it, I did understand and summarize some tips that can speed up our subsequent development. 1. some tips in useState When we use react to develop function comppoent, we can’t help but see useState everywhere, so what are the pitfalls and things to watch out for in
nextjs how not to show data of next_data
nextjs provides the getServerSideProps method (previously called getInitialProps method) to request data before rendering the page. However, the nextjs framework will pass the requested data to the front-end via a script tag in order to keep the front-end and back-end in sync. 1 <script id="__NEXT_DATA__" type="application/json"></script> But sometimes, we don’t want to expose some raw data to the front-end page, such as some blog sites, news sites, etc., which basically
Various ways to determine if an element exists in an array
In js development, we often encounter the need to determine whether a certain element exists in an array. In fact, there are many ways to determine this, so let’s understand them one by one. Let’s define an array first. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 const arr = [ 13, false, 'abcd', undefined, 13, null, NaN, [1, 2], { a: 123
Native methods for manipulating cookies - cookieStore
We usually use document.cookie for operations such as adding, deleting, and checking cookies. Here we introduce a new method cookieStore. 1. How to manipulate cookies in general document.cookie gets all the cookie strings for the current domain. Each cookie is separated by a semicolon. 1 document.cookie; // "a=1; b=2; c=wenzi" To manipulate cookies, you are generally manipulating document.cookie. Here is a piece of code that I commonly use. 1 2
In-depth understanding of Proxy in js
Proxy is a syntax added to the es2015 standard specification, and it is likely that you have only heard of it but not used it - after all, Proxy features cannot be used easily given the compatibility issues. But now, with each browser’s update iteration, Proxy’s support is getting higher and higher. Vue3 has replaced Object.defineProperty with Proxy for responsiveness, and mobx has been using Proxy for proxying since version
Use the http module in nodejs to implement a few super useful tools
nodejs makes it easy for us front-end developers to do some server-side operations seamlessly. Other back-end languages like php, golang, java, etc. require a certain amount of learning cost, while nodejs is customized for front-end developers. In nodejs, a native http module is provided, and we can use the http module to make a few common widgets that can greatly facilitate our work. 1. A simple HTTP service Building an
Rust 2021 Survey: Interesting but Challenging
The results of the Rust 2021 survey are now available. Ninety percent of respondents said they use Rust, 5% said they have used Rust in the past but no longer use it, and 4% said they have not used Rust at all.
The survey was conducted in December 2021 and is based on feedback from 9,354 respondents. Officials noted that the Rust community is growing, and the survey had the highest number of complete survey responses ever, beating last year’s total by about 1,500.
Some efficient magic operators in JS
Now JavaScript has added some operators that are easier and more efficient to manipulate without some additional processing. Nowadays, JavaScript releases a new version every year, and it adds some new operators that are more convenient and efficient to use. Today we’ll take a look at some of these efficient magic operators. 1. Optional Chain Operators Previously, when we wanted to use a property with a deeper structure, and we