`basic_filebuf`、`basic_ifstream`、`basic_ofstream`和 `basic_fstream`。

C++ 文件 I/O 模板類深度解析

文章目錄

  • C++ 文件 I/O 模板類深度解析
    • 1. basic_filebuf 深度解析
      • 1.1 類模板定義詳解
      • 1.2 關鍵成員變量
      • 1.3 核心成員函數實現原理
        • 1.3.1 open() 函數實現
        • 1.3.2 overflow() 函數實現
      • 1.4 完整示例:自定義緩沖策略
    • 2. basic_ifstream 深度解析
      • 2.1 類繼承體系
      • 2.2 構造函數實現原理
      • 2.3 文件讀取機制
      • 2.4 完整示例:大文件分塊讀取
    • 3. basic_ofstream 深度解析
      • 3.1 類繼承體系
      • 3.2 文件寫入優化策略
      • 3.3 完整示例:高性能日志系統
    • 4. basic_fstream 深度解析
      • 4.1 類繼承體系
      • 4.2 隨機訪問實現原理
      • 4.3 完整示例:數據庫式文件操作
    • 5. 高級主題:自定義文件系統適配器
    • 6. 性能優化技巧
      • 6.1 緩沖區大小優化
      • 6.2 內存映射文件示例

我將從底層原理到高級應用,全面詳細地解析 C++ 文件 I/O 模板類,包括 basic_filebufbasic_ifstreambasic_ofstreambasic_fstream

1. basic_filebuf 深度解析

basic_filebuf是文件 I/O 的核心緩沖類,繼承自 basic_streambuf

1.1 類模板定義詳解

template<class CharT,                       // 字符類型 (char, wchar_t 等)class Traits = std::char_traits<CharT> // 字符特性類
> 
class basic_filebuf : public std::basic_streambuf<CharT, Traits>

1.2 關鍵成員變量

protected:FILE* _M_file;      // 底層C文件指針bool _M_is_open;    // 文件打開狀態__c_locale _M_ctype;// 本地化信息// 緩沖區管理相關成員...

1.3 核心成員函數實現原理

1.3.1 open() 函數實現
basic_filebuf<CharT, Traits>* 
basic_filebuf<CharT, Traits>::open(const char* s, ios_base::openmode mode)
{if (is_open())return nullptr;// 轉換打開模式為C風格const char* c_mode = translate_mode(mode);if (!c_mode)return nullptr;// 打開文件_M_file = fopen(s, c_mode);if (!_M_file)return nullptr;_M_is_open = true;// 初始化緩沖區_M_initialize_buffers();return this;
}
1.3.2 overflow() 函數實現

處理輸出緩沖區滿的情況:

typename basic_filebuf<CharT, Traits>::int_type
basic_filebuf<CharT, Traits>::overflow(int_type c)
{if (!_M_is_open)return Traits::eof();// 刷新緩沖區if (_M_write_buf_size > 0) {if (fwrite(_M_write_buf, sizeof(CharT), _M_write_buf_size, _M_file) != _M_write_buf_size)return Traits::eof();_M_write_buf_size = 0;}// 如果有額外字符,直接寫入if (!Traits::eq_int_type(c, Traits::eof())) {CharT ch = Traits::to_char_type(c);if (fwrite(&ch, sizeof(CharT), 1, _M_file) != 1)return Traits::eof();}return Traits::not_eof(c);
}

1.4 完整示例:自定義緩沖策略

#include <iostream>
#include <fstream>
#include <vector>template<typename CharT, typename Traits = std::char_traits<CharT>>
class custom_filebuf : public std::basic_filebuf<CharT, Traits> {
public:using int_type = typename Traits::int_type;// 自定義緩沖區大小explicit custom_filebuf(size_t buf_size = 1024) : buffer(buf_size) {this->setp(buffer.data(), buffer.data() + buffer.size());}protected:// 重寫 overflow 實現自定義刷新策略int_type overflow(int_type c) override {if (!this->is_open())return Traits::eof();// 獲取當前緩沖區內容CharT* base = this->pbase();CharT* current = this->pptr();// 寫入緩沖區內容if (base && current > base) {if (fwrite(base, sizeof(CharT), current - base, this->_M_file) != static_cast<size_t>(current - base))return Traits::eof();}// 處理額外字符if (!Traits::eq_int_type(c, Traits::eof())) {CharT ch = Traits::to_char_type(c);if (fwrite(&ch, sizeof(CharT), 1, this->_M_file) != 1)return Traits::eof();}// 重置緩沖區指針this->setp(buffer.data(), buffer.data() + buffer.size());return Traits::not_eof(c);}private:std::vector<CharT> buffer;
};int main() {// 使用自定義文件緩沖custom_filebuf<char> cfb;cfb.open("custom_buffer.txt", std::ios_base::out);std::ostream os(&cfb);for (int i = 0; i < 1000; ++i) {os << "Line " << i << "\n";}cfb.close();return 0;
}

2. basic_ifstream 深度解析

2.1 類繼承體系

basic_istream<CharT, Traits>↑
basic_ifstream<CharT, Traits>

2.2 構造函數實現原理

template<typename CharT, typename Traits>
basic_ifstream<CharT, Traits>::basic_ifstream(const char* filename, ios_base::openmode mode): basic_istream<CharT, Traits>(&_M_filebuf),_M_filebuf()
{if (filename && !_M_filebuf.open(filename, mode | ios_base::in)) {this->setstate(ios_base::failbit);}
}

2.3 文件讀取機制

template<typename CharT, typename Traits>
std::streamsize 
basic_ifstream<CharT, Traits>::readsome(CharT* s, std::streamsize n)
{// 檢查流狀態if (!this->good())return 0;// 獲取緩沖區中可用數據std::streamsize avail = this->rdbuf()->in_avail();if (avail <= 0)return 0;// 讀取不超過n的字符std::streamsize count = std::min(n, avail);return this->rdbuf()->sgetn(s, count);
}

2.4 完整示例:大文件分塊讀取

#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>template<typename CharT>
void read_large_file(const std::basic_string<CharT>& filename, size_t chunk_size = 4096) {std::basic_ifstream<CharT> ifs(filename, std::ios_base::binary);if (!ifs) {std::basic_ostream<CharT>(std::cerr) << "Failed to open file\n";return;}auto start = std::chrono::high_resolution_clock::now();std::vector<CharT> buffer(chunk_size);size_t total_bytes = 0;while (ifs) {ifs.read(buffer.data(), chunk_size);std::streamsize count = ifs.gcount();if (count > 0) {total_bytes += count;// 處理數據塊...}}auto end = std::chrono::high_resolution_clock::now();auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);std::cout << "Read " << total_bytes << " bytes in " << duration.count() << " ms\n";
}int main() {// 讀取大文件(4KB塊)read_large_file<char>("large_file.bin");// 寬字符版本read_large_file<wchar_t>(L"large_wide_file.bin");return 0;
}

3. basic_ofstream 深度解析

3.1 類繼承體系

basic_ostream<CharT, Traits>↑
basic_ofstream<CharT, Traits>

3.2 文件寫入優化策略

template<typename CharT, typename Traits>
basic_ofstream<CharT, Traits>& 
basic_ofstream<CharT, Traits>::write(const CharT* s, std::streamsize n)
{// 檢查流狀態if (!this->good())return *this;// 嘗試直接寫入緩沖區std::streamsize remaining = n;while (remaining > 0) {std::streamsize avail = this->rdbuf()->sputn(s, remaining);if (avail <= 0) {this->setstate(ios_base::badbit);break;}s += avail;remaining -= avail;}return *this;
}

3.3 完整示例:高性能日志系統

#include <iostream>
#include <fstream>
#include <string>
#include <thread>
#include <mutex>
#include <vector>template<typename CharT>
class ThreadSafeLogger {
public:explicit ThreadSafeLogger(const std::basic_string<CharT>& filename): _ofs(filename, std::ios_base::app) {}~ThreadSafeLogger() {std::lock_guard<std::mutex> lock(_mutex);_ofs.close();}void log(const std::basic_string<CharT>& message) {std::lock_guard<std::mutex> lock(_mutex);if (_ofs) {auto now = std::chrono::system_clock::now();auto time = std::chrono::system_clock::to_time_t(now);_ofs << std::put_time(std::localtime(&time), "%Y-%m-%d %X") << " | " << message << '\n';// 立即刷新以確保日志及時寫入_ofs.flush();}}private:std::basic_ofstream<CharT> _ofs;std::mutex _mutex;
};void test_logger(ThreadSafeLogger<char>& logger, int thread_id) {for (int i = 0; i < 100; ++i) {logger.log("Thread " + std::to_string(thread_id) + " log message " + std::to_string(i));}
}int main() {ThreadSafeLogger<char> logger("thread_safe.log");std::vector<std::thread> threads;for (int i = 0; i < 10; ++i) {threads.emplace_back(test_logger, std::ref(logger), i);}for (auto& t : threads) {t.join();}return 0;
}

4. basic_fstream 深度解析

4.1 類繼承體系

basic_iostream<CharT, Traits>↑
basic_fstream<CharT, Traits>

4.2 隨機訪問實現原理

template<typename CharT, typename Traits>
typename basic_fstream<CharT, Traits>::pos_type
basic_fstream<CharT, Traits>::seekg(pos_type pos)
{if (!this->fail()) {pos_type new_pos = this->rdbuf()->pubseekpos(pos, std::ios_base::in);if (new_pos == pos_type(-1))this->setstate(std::ios_base::failbit);return new_pos;}return pos_type(-1);
}

4.3 完整示例:數據庫式文件操作

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstring>template<typename CharT>
class SimpleFileDB {struct RecordHeader {size_t id;size_t length;bool deleted;};public:explicit SimpleFileDB(const std::basic_string<CharT>& filename): _filename(filename), _next_id(1) {load_index();}~SimpleFileDB() {save_index();}size_t insert(const std::basic_string<CharT>& data) {std::basic_fstream<CharT> fs(_filename, std::ios_base::in | std::ios_base::out | std::ios_base::binary);if (!fs) {fs.open(_filename, std::ios_base::out | std::ios_base::binary);fs.close();fs.open(_filename, std::ios_base::in | std::ios_base::out | std::ios_base::binary);}RecordHeader header{_next_id++, data.length(), false};// 移動到文件末尾fs.seekp(0, std::ios_base::end);// 寫入記錄頭fs.write(reinterpret_cast<CharT*>(&header), sizeof(header));// 寫入數據fs.write(data.data(), data.length());// 更新索引_index.push_back({header.id, fs.tellp() - static_cast<std::streampos>(data.length())});return header.id;}bool get(size_t id, std::basic_string<CharT>& out) {auto it = std::find_if(_index.begin(), _index.end(), [id](const auto& entry) { return entry.first == id; });if (it == _index.end())return false;std::basic_ifstream<CharT> ifs(_filename, std::ios_base::binary);ifs.seekg(it->second);RecordHeader header;ifs.read(reinterpret_cast<CharT*>(&header), sizeof(header));if (header.deleted)return false;out.resize(header.length);ifs.read(&out[0], header.length);return true;}bool remove(size_t id) {auto it = std::find_if(_index.begin(), _index.end(), [id](const auto& entry) { return entry.first == id; });if (it == _index.end())return false;std::basic_fstream<CharT> fs(_filename, std::ios_base::in | std::ios_base::out | std::ios_base::binary);fs.seekp(it->second + offsetof(RecordHeader, deleted));bool deleted = true;fs.write(reinterpret_cast<CharT*>(&deleted), sizeof(deleted));return true;}private:void load_index() {std::basic_ifstream<CharT> ifs(_filename, std::ios_base::binary);if (!ifs)return;while (ifs) {std::streampos pos = ifs.tellg();RecordHeader header;ifs.read(reinterpret_cast<CharT*>(&header), sizeof(header));if (!ifs)break;_index.emplace_back(header.id, pos);_next_id = std::max(_next_id, header.id + 1);// 跳過數據ifs.seekg(header.length, std::ios_base::cur);}}void save_index() {// 在實際應用中,可以保存索引到單獨文件}std::basic_string<CharT> _filename;std::vector<std::pair<size_t, std::streampos>> _index;size_t _next_id;
};int main() {SimpleFileDB<char> db("simple_db.dat");size_t id1 = db.insert("First record data");size_t id2 = db.insert("Second record data");std::string data;if (db.get(id1, data)) {std::cout << "Record " << id1 << ": " << data << "\n";}db.remove(id2);if (!db.get(id2, data)) {std::cout << "Record " << id2 << " not found (deleted)\n";}return 0;
}

5. 高級主題:自定義文件系統適配器

#include <iostream>
#include <streambuf>
#include <vector>
#include <memory>// 內存文件系統適配器
template<typename CharT, typename Traits = std::char_traits<CharT>>
class memory_filebuf : public std::basic_streambuf<CharT, Traits> {
public:using int_type = typename Traits::int_type;explicit memory_filebuf(std::vector<CharT>& storage): _storage(storage), _pos(0) {this->setg(_storage.data(), _storage.data(), _storage.data() + _storage.size());this->setp(_storage.data(), _storage.data() + _storage.size());}protected:// 讀取操作int_type underflow() override {if (this->gptr() == this->egptr()) {if (_pos >= _storage.size())return Traits::eof();this->setg(_storage.data(), _storage.data() + _pos, _storage.data() + _storage.size());}return Traits::to_int_type(*this->gptr());}// 寫入操作int_type overflow(int_type c) override {if (!Traits::eq_int_type(c, Traits::eof())) {if (_pos >= _storage.size()) {_storage.push_back(Traits::to_char_type(c));} else {_storage[_pos] = Traits::to_char_type(c);}_pos++;return c;}return Traits::not_eof(c);}// 定位操作std::streampos seekpos(std::streampos pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override {if (pos < 0 || pos > static_cast<std::streampos>(_storage.size()))return -1;_pos = static_cast<size_t>(pos);if (which & std::ios_base::in) {this->setg(_storage.data(), _storage.data() + _pos, _storage.data() + _storage.size());}if (which & std::ios_base::out) {this->setp(_storage.data() + _pos, _storage.data() + _storage.size());}return pos;}private:std::vector<CharT>& _storage;size_t _pos;
};template<typename CharT>
class memory_file : public std::basic_iostream<CharT> {
public:explicit memory_file(std::vector<CharT>& storage): std::basic_iostream<CharT>(new memory_filebuf<CharT>(storage)),_buf(static_cast<memory_filebuf<CharT>*>(this->rdbuf())) {}~memory_file() {this->rdbuf(nullptr);delete _buf;}private:memory_filebuf<CharT>* _buf;
};int main() {std::vector<char> storage;memory_file<char> mfile(storage);// 寫入數據mfile << "Hello, Memory File!\n";mfile << "This is a test.\n";// 讀取數據mfile.seekg(0);std::string line;while (std::getline(mfile, line)) {std::cout << line << "\n";}return 0;
}

6. 性能優化技巧

6.1 緩沖區大小優化

template<typename CharT>
void optimize_buffer_size(const std::basic_string<CharT>& filename) {// 測試不同緩沖區大小對性能的影響const size_t file_size = 100 * 1024 * 1024; // 100MBconst std::vector<size_t> buffer_sizes = {512, 1024, 4096, 8192, 16384, 65536};// 創建測試文件{std::basic_ofstream<CharT> ofs(filename, std::ios_base::binary);std::vector<CharT> data(file_size, 'A');ofs.write(data.data(), data.size());}// 測試不同緩沖區大小for (size_t buf_size : buffer_sizes) {std::vector<CharT> buffer(buf_size);auto start = std::chrono::high_resolution_clock::now();std::basic_ifstream<CharT> ifs(filename, std::ios_base::binary);ifs.rdbuf()->pubsetbuf(buffer.data(), buf_size);size_t total_read = 0;while (ifs) {ifs.read(buffer.data(), buf_size);total_read += ifs.gcount();}auto end = std::chrono::high_resolution_clock::now();auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);std::cout << "Buffer size: " << buf_size << " bytes, Time: " << duration.count() << " ms\n";}
}

6.2 內存映射文件示例

#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endiftemplate<typename CharT>
class memory_mapped_file {
public:explicit memory_mapped_file(const std::basic_string<CharT>& filename) {
#ifdef _WIN32_hFile = CreateFile(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);if (_hFile == INVALID_HANDLE_VALUE)throw std::runtime_error("Failed to open file");_hMapping = CreateFileMapping(_hFile, NULL, PAGE_READONLY, 0, 0, NULL);if (_hMapping == NULL) {CloseHandle(_hFile);throw std::runtime_error("Failed to create file mapping");}_data = static_cast<const CharT*>(MapViewOfFile(_hMapping, FILE_MAP_READ, 0, 0, 0));if (_data == NULL) {CloseHandle(_hMapping);CloseHandle(_hFile);throw std::runtime_error("Failed to map view of file");}DWORD sizeHigh;_size = GetFileSize(_hFile, &sizeHigh);_size |= (static_cast<uint64_t>(sizeHigh) << 32);
#else_fd = open(filename.c_str(), O_RDONLY);if (_fd == -1)throw std::runtime_error("Failed to open file");struct stat sb;if (fstat(_fd, &sb) == -1) {close(_fd);throw std::runtime_error("Failed to get file size");}_size = sb.st_size;_data = static_cast<const CharT*>(mmap(NULL, _size, PROT_READ, MAP_PRIVATE, _fd, 0));if (_data == MAP_FAILED) {close(_fd);throw std::runtime_error("Failed to map file");}
#endif}~memory_mapped_file() {
#ifdef _WIN32UnmapViewOfFile(_data);CloseHandle(_hMapping);CloseHandle(_hFile);
#elsemunmap(const_cast<CharT*>(_data), _size);close(_fd);
#endif}const CharT* data() const { return _data; }size_t size() const { return _size; }private:const CharT* _data;size_t _size;
#ifdef _WIN32HANDLE _hFile;HANDLE _hMapping;
#elseint _fd;
#endif
};int main() {try {memory_mapped_file<char> mmf("large_file.bin");std::cout << "File size: " << mmf.size() << " bytes\n";// 可以直接訪問文件內容,無需讀取操作const char* data = mmf.data();// 處理數據...} catch (const std::exception& e) {std::cerr << "Error: " << e.what() << "\n";}return 0;
}

以上內容全面深入地解析了 C++ 文件 I/O 模板類的各個方面,從基礎用法到高級特性,從性能優化到自定義實現,涵蓋了文件操作的所有關鍵知識點。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/97355.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/97355.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/97355.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

計算機畢設 java 阿歹果園養雞場管理系統 基于 SSM 框架的果園養雞場全流程管理系統設計與實現 Java+MySQL 的養殖生產與進銷存一體化平臺開發

計算機畢設 java 阿歹果園養雞場管理系統ky7dc9 &#xff08;配套有源碼 程序 mysql數據庫 論文&#xff09;本套源碼可以先看具體功能演示視頻領取&#xff0c;文末有聯xi 可分享 隨著農業養殖規模化發展&#xff0c;傳統果園養雞場依賴人工記錄、紙質臺賬的管理模式&#xf…

生成式BI工具(WrenAI)

生成式 BI 工具支持自然語言查詢數據庫&#xff0c;自動生成 SQL 與可視化圖表&#xff0c;被金融分析師和數據科學家廣泛采用。 WrenAI是由Canner團隊開發的開源生成式BI&#xff08;GenBI&#xff09;智能體&#xff0c;致力于通過自然語言交互實現數據庫查詢、可視化生成和洞…

論文Review 3DGS PGSR | TVCG2024 ZJU-3DV | 幾何約束的3DGS表面重建

基本信息 題目&#xff1a;PGSR: Planar-based Gaussian Splatting for Efficient and High-Fidelity Surface Reconstruction 來源&#xff1a;TVCG2024 學校&#xff1a;ZJU-3DV 是否開源&#xff1a;https://github.com/zju3dv/PGSR 摘要&#xff1a;3DGS表面重建 最近…

最新After Effects2025下載安裝(含安裝包)AE 2025 保姆級下載一鍵安裝圖文教程

文章目錄一、After Effects 2025下載二、After Effects 2025安裝教程三、核心功能升級詳解四、系統配置與兼容性說明一、After Effects 2025下載 ①夸克網盤下載鏈接&#xff1a;https://pan.quark.cn/s/a06e6200e64c 二、After Effects 2025安裝教程 1.解壓安裝包:找到下載…

【網絡安全領域】邊界安全是什么?目前的發展及應用場景

在網絡安全領域&#xff0c;邊界安全&#xff08;Perimeter Security&#xff09; 是指圍繞企業或組織網絡的 “物理與邏輯邊界” 構建的防護體系&#xff0c;核心目標是阻止未授權訪問從外部網絡&#xff08;如互聯網、合作方網絡&#xff09;侵入內部可信網絡&#xff0c;同時…

虛擬機快照對內存與磁盤空間的影響

核心概念&#xff1a;快照是什么&#xff1f;虛擬機快照捕獲的是在某個特定時間點上虛擬機的完整狀態。這包括&#xff1a;磁盤狀態&#xff1a;虛擬磁盤的數據。內存狀態&#xff1a;當時虛擬機內存中的所有內容&#xff08;如果選擇&#xff09;。配置狀態&#xff1a;虛擬機…

免費開源的 Gemini 2.5 Flash 圖片生成器

免費開源的 Gemini 2.5 Flash 圖片生成器&#xff1a;gemini-nano-banana 項目詳解 在 AI 圖片生成領域&#xff0c;大多數工具要么收費昂貴&#xff0c;要么需要復雜的配置。今天為大家介紹一個完全免費開源的解決方案——gemini-nano-banana&#xff0c;一個基于 Google Gemi…

介紹分布式事務之Seata

簡介 Seata 是一款開源的分布式事務解決方案&#xff0c;致力于提供高性能和簡單易用的分布式事務服務。Seata 將為用戶提供了 AT、TCC、SAGA 和 XA 事務模式&#xff0c;為用戶打造一站式的分布式事務解決方案。 &#x1f680; 一、Seata 的四種主要模式 Seata 提供的分布式事…

安卓/ios按鍵精靈腳本開發工具:OpenCV.FindImgAll命令介紹

函數名稱OpenCV.FindImgAll 找圖返回全部結果函數功能使用OpenCV多尺度模板找圖&#xff0c;返回全部結果與FindPic的區別&#xff1a;OpenCV找圖&#xff1a;基于特征相似性的找圖&#xff0c;允許一定幾何形變或顏色差異&#xff0c;從而提高多分辨率容兼及抗干擾能力&#x…

Linux時間處理函數

gettimeofday 是 Linux 系統中一個用于獲取當前時間的系統調用函數。它能夠獲取從 Unix 紀元&#xff08;1970年1月1日 00:00:00 UTC&#xff09;到當前時刻的秒數和微秒數。函數原型#include <sys/time.h>int gettimeofday(struct timeval *tv, struct timezone *tz);參…

C++ 面試高頻考點 力扣 34. 在排序數組中查找元素的第一個和最后一個位置 二分查找左右端點 題解 每日一題

文章目錄二分查找進階&#xff0c;精準定位左右邊界題目描述先踩坑&#xff1a;樸素二分為什么搞不定重復元素&#xff1f;第一步&#xff1a;找左邊界——如何定位“第一個target”&#xff1f;第二步&#xff1a;找右邊界——如何定位“最后一個target”&#xff1f;完整代碼…

在word以及latex中引用zotero中的參考文獻

背景 如何在word以及latex中引用zotero中的參考文獻 歷史參考 恢復Zotero軟件內的誤刪條目數據/文獻-CSDN博客使用zotero保存 CNKI知網文章時發生錯誤。改為嘗試用 Save as Webpage 保存。-CSDN博客 word 在word中引用zotero中的參考文獻 打開word&#xff0c;點擊引用 經典…

docker 部署Skywalking

創建網絡 docker network create skywalking-network docker compose 安裝SkyWalking docker-compose.yaml 文件 version: "3" services:# SkyWalking OAP server with Elasticsearch storageskywalking-oap:image: apache/skywalking-oap-server:8.9.0container…

動態UI的秘訣:React中的條件渲染

動態UI的秘訣&#xff1a;React中的條件渲染 作者&#xff1a;碼力無邊各位React探險家&#xff0c;歡迎回到我們的《React奇妙之旅》&#xff01;我是你們的老朋友碼力無邊。在之前的旅程中&#xff0c;我們已經學會了如何創建組件、傳遞數據&#xff08;Props&#xff09;、管…

ubuntu掛載外接硬盤

查看找到硬盤sudo fdisk -l例如&#xff1a;名字為&#xff1a;/dev/sda創建掛載點sudo mkdir -p /2TSSD手動掛載&#xff08;單次生效&#xff0c;關機會失效&#xff09;sudo mount /dev/sda1 /2TSSD開機自動掛載&#xff08;永遠生效&#xff0c;關機會失效&#xff09;S1&a…

數學思想 | 數學思維過程對象封裝

注&#xff1a;本文為 “數學思維過程對象封裝” 相關譯文。 英文引文&#xff0c;機翻未校。 略作重排&#xff0c;如有內容異常&#xff0c;請看原文。 What is the object of the encapsulation of a process? 過程封裝的對象是什么&#xff1f; David Tall#, Michael Th…

常見視頻封裝格式對比

一、核心概念&#xff1a;封裝格式 vs 編碼格式 編碼格式 (Codec): 例如 H.264, H.265 (HEVC), AV1, VP9。它負責對原始視頻和音頻數據進行壓縮&#xff0c;是決定視頻體積和清晰度的關鍵。封裝格式 (Container): 例如 MP4, MKV, AVI。它負責將已經壓縮好的視頻、音頻、字幕等打…

Java實現PDF表格轉換為CSV

在很多企業辦公和數據分析的場景中&#xff0c;PDF 中常常存放著報表、清單或統計數據。相比 PDF&#xff0c;CSV 文件 更易于在 Excel 或數據庫中進行進一步處理。因此&#xff0c;我們常常需要一種方式&#xff0c;將 PDF 中的表格數據批量抽取并導出為 CSV 文件。 本文將介…

具有類人先驗知識的 Affordance-覺察機器人靈巧抓取

25年8月來自武漢大學、阿里達摩院、湖畔研究中心、浙大和清華的論文“Towards Affordance-Aware Robotic Dexterous Grasping with Human-like Priors”。 能夠泛化抓取目標的靈巧手是開發通用具身人工智能的基礎。然而&#xff0c;之前的方法僅僅關注低級抓取穩定性指標&#…

項目管理的關鍵成功因素

項目管理的關鍵成功因素包括&#xff1a;目標明確、科學規劃、有效溝通、資源保障、風險管理、團隊協作、持續監控與總結改進。目標明確保證方向不偏移、科學規劃確保執行有章可循、有效溝通減少誤解與沖突、資源保障提供堅實支撐、風險管理幫助預防問題、團隊協作提升整體效率…