|
Download cpp/cpp-memory.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-memory.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-memory.jsonl
-
curl -L -o cpp-memory.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-memory.jsonl
1.36 kB
| {"type": "session", "harness": "opencode", "id": "cpp-memory", "name": "C++ Smart Pointers and Memory Management"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}} | |
| {"type": "message", "message": {"role": "user", "content": "Explain C++ smart pointers and memory safety"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "Smart pointers: RAII-based automatic memory management.\n\nstd::unique_ptr<T>: exclusive ownership, zero overhead, move-only.\n- std::make_unique<T>(args...) for exception safety\n- Custom deleters: unique_ptr<T, decltype(&free)>\n\nstd::shared_ptr<T>: reference-counted shared ownership.\n- std::make_shared<T>: single allocation (control block + object)\n- weak_ptr<T>: non-owning reference, breaks cycles\n- Control block: reference count + weak count + deleter\n\nstd::atomic<int> for thread-safe reference counting.\n\nMemory safety issues:\n- Use-after-free: dangling pointers/references\n- Double-free: multiple deletions\n- Buffer overflows: unchecked array access\n- Dangling references: references to destroyed objects\n\nBest practices:\n- Prefer stack allocation and containers\n- Use unique_ptr by default, shared_ptr only when needed\n- Avoid raw new/delete\n- Use std::optional for nullable values\n- std::string_view for non-owning string references"}} | |