https://www.gravatar.com/avatar/206912d6900c65386f24516df605c206?s=240&d=mp

Kourtney's Space

Deep Copy and Shallow Copy

Shallow Copy

Copies as little as possible.
A new structure created by a shallow copy has the same structure as the old one,
and they share the memory address of elements.

For example, in Java:

int[] arr1 = {1, 2, 3};
int[] arr2 = arr1;

arr2 is a shallow copy of arr1.

C++ Container Characteristics and Usage Scenarios - array, vector, deque, list, forward_list

Introduction

C++ provides various containers to store and manage data,
each with its unique characteristics and applicable scenarios.
This article will delve into five common sequence containers: array, vector, deque, list, and forward_list,
comparing their features, performance, and offering selection advice.

Array

std::array is a fixed-size array introduced in C++11,
combining the performance of C-style arrays with the interface of STL containers.

Characteristics

  • Fixed Size: Size is determined at compile time and cannot be changed dynamically.
  • Stack Allocation: Typically allocates memory on the stack, offering high performance.
  • Random Access: Supports O(1) time complexity for random access.
  • Iterator Support: Provides iterators, allowing use with STL algorithms.

When to Use

  • When the data size is known and fixed.
  • When pursuing ultimate performance, avoiding heap allocation overhead.
  • When interoperability with C-style arrays is required.

Example

#include <array>
#include <iostream>
#include <numeric> // For std::accumulate

int main() {
    std::array<int, 5> my_array = {1, 2, 3, 4, 5};

    // Access elements
    std::cout << "Element at index 2: " << my_array[2] << std::endl; // Output: 3

    // Iteration
    for (int& x : my_array) {
        x *= 2;
    }

    // Sum
    int sum = std::accumulate(my_array.begin(), my_array.end(), 0);
    std::cout << "Sum of elements: " << sum << std::endl; // Output: 30

    return 0;
}

Vector

std::vector is a dynamic array that can change its size dynamically at runtime.
It is the most commonly used and flexible sequence container in C++.

HA Cluster Notes and Application Design

When designing systems with higher traffic, you will eventually encounter cluster-related issues.

Cluster

A collection of one or more machines (nodes) with three different purposes:

Load Balancing

Allows multiple machines to share tasks as evenly as possible, accelerating application execution.

High Availability (HA)

For high availability and redundancy, if one machine suddenly fails, others can take over.

High Performance Computing

High-performance/parallel computing systems, abbreviated as HPC clusters, combine the hardware of multiple machines to increase computing power, used to solve tasks that a single machine cannot handle.

Common DNS Resource Records

Each DNS zone in a DNS server has a zone file.
A DNS zone is usually a single domain (though not always).
A zone file is composed of many DNS resource records (RRs).
There are many different types of RRs.
Let’s record some common ones.

A record

Maps a hostname to an IPv4 address. (32-bit)

hostname IN A xxx.xxx.xxx.xxx

RDBMS and NoSQL Differences Notes

RDBMS

Relational Database Management System

  • Used when there are strong Relations between data:
    • Design a schema that is unlikely to change, relating tables to each other, then you can retrieve the desired data through SQL.
  • Used when data correctness is very important:
    • Usually provides ACID properties.
  • Changing the schema is a huge undertaking:
    • Requires updating the table schema and migrating data.
    • All programs that use the table with the changed schema need to be modified.