Initial commit
This commit is contained in:
53
plugins/windows-development/skills/cpp-best-practices.md
Normal file
53
plugins/windows-development/skills/cpp-best-practices.md
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
name: C++最佳实践
|
||||
description: 现代C++编程规范和性能优化
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
# C++ Best Practices Skill
|
||||
|
||||
## Overview
|
||||
Modern C++ programming best practices for high-performance Windows development.
|
||||
|
||||
## Key Principles
|
||||
|
||||
### RAII (Resource Acquisition Is Initialization)
|
||||
```cpp
|
||||
class FileHandle {
|
||||
HANDLE handle_;
|
||||
public:
|
||||
FileHandle(const wchar_t* path) {
|
||||
handle_ = CreateFileW(path, ...);
|
||||
}
|
||||
~FileHandle() {
|
||||
if (handle_ != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(handle_);
|
||||
}
|
||||
}
|
||||
// Disable copying, enable moving
|
||||
FileHandle(const FileHandle&) = delete;
|
||||
FileHandle(FileHandle&& other) noexcept
|
||||
: handle_(other.handle_) {
|
||||
other.handle_ = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### Smart Pointers
|
||||
- Use `std::unique_ptr` for exclusive ownership
|
||||
- Use `std::shared_ptr` sparingly
|
||||
- Avoid `std::weak_ptr` unless breaking cycles
|
||||
|
||||
### Modern C++ Features
|
||||
- Range-based for loops
|
||||
- Auto type deduction
|
||||
- Lambda expressions
|
||||
- Structured bindings (C++17)
|
||||
- Concepts (C++20)
|
||||
|
||||
## Performance Tips
|
||||
1. Avoid unnecessary copying (use std::move)
|
||||
2. Reserve container capacity
|
||||
3. Use string_view for read-only strings
|
||||
4. Inline hot functions
|
||||
5. Profile before optimizing
|
||||
37
plugins/windows-development/skills/windows-kernel-basics.md
Normal file
37
plugins/windows-development/skills/windows-kernel-basics.md
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: Windows内核基础
|
||||
description: IRQL、内存池、同步机制
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
# Windows Kernel Development Basics
|
||||
|
||||
## IRQL Levels
|
||||
- PASSIVE_LEVEL (0): Normal execution
|
||||
- APC_LEVEL (1): Asynchronous Procedure Calls
|
||||
- DISPATCH_LEVEL (2): DPC and scheduler
|
||||
- DEVICE_IRQL (3+): Hardware interrupts
|
||||
|
||||
## Memory Pools
|
||||
```c
|
||||
// NonPagedPool: Always resident, use at DISPATCH_LEVEL
|
||||
PVOID buffer = ExAllocatePool2(POOL_FLAG_NON_PAGED, size, 'Tag1');
|
||||
|
||||
// PagedPool: Can be paged out, use at PASSIVE_LEVEL
|
||||
PVOID buffer = ExAllocatePool2(POOL_FLAG_PAGED, size, 'Tag2');
|
||||
|
||||
// Don't forget to free
|
||||
ExFreePoolWithTag(buffer, 'Tag1');
|
||||
```
|
||||
|
||||
## Synchronization
|
||||
- Spin Lock: High IRQL, short duration
|
||||
- Mutex: PASSIVE_LEVEL only
|
||||
- Fast Mutex: Similar to kernel mutex
|
||||
- Event: Signal/Wait mechanism
|
||||
|
||||
## Common Pitfalls
|
||||
- Accessing paged memory at DISPATCH_LEVEL
|
||||
- Forgetting to dereference objects
|
||||
- Not handling IRP cancellation
|
||||
- Memory leaks (use Driver Verifier)
|
||||
Reference in New Issue
Block a user