SrsUniquePtr does not support array or object created by malloc, because
we only use delete to dispose the resource. You can use a custom
function to free the memory allocated by malloc or other allocators.
```cpp
char* p = (char*)malloc(1024);
SrsUniquePtr<char> ptr(p, your_free_chars);
```
This is used to replace the SrsAutoFreeH. For example:
```cpp
addrinfo* r = NULL;
SrsAutoFreeH(addrinfo, r, freeaddrinfo);
getaddrinfo("127.0.0.1", NULL, &hints, &r);
```
Now, this can be replaced by:
```cpp
addrinfo* r = NULL;
getaddrinfo("127.0.0.1", NULL, &hints, &r);
SrsUniquePtr<addrinfo> r2(r, freeaddrinfo);
```
Please aware that there is a slight difference between SrsAutoFreeH and
SrsUniquePtr. SrsAutoFreeH will track the address of pointer, while
SrsUniquePtr will not.
```cpp
addrinfo* r = NULL;
SrsAutoFreeH(addrinfo, r, freeaddrinfo); // r will be freed even r is changed later.
SrsUniquePtr<addrinfo> ptr(r, freeaddrinfo); // crash because r is an invalid pointer.
```
---------
Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
Debug with VSCode
Support run and debug with VSCode.
SRS
Install the following extensions:
- CMake Tools
- CodeLLDB
- C/C++ Extension Pack
Open the folder like ~/git/srs in VSCode.
Run commmand > CMake: Configure to configure the project.
Note: You can press
Ctrl+R, then typeCMake: Configurethen selectClangas the toolchain.
Note: The
settings.jsonis used to configure the cmake. It will use${workspaceFolder}/trunk/ide/srs_clion/CMakeLists.txtand${workspaceFolder}/trunk/ide/vscode-buildas the source file and build directory.
Click the Run > Run Without Debugging button to start the server.
Note: The
launch.jsonis used for running and debugging. The build will output the binary to${workspaceFolder}/trunk/ide/vscode-build/srs.
Proxy
Install the following extensions:
- Go
Open the folder like ~/git/srs in VSCode.
Select the View > Run and select Launch srs-proxy to start the proxy server.
Click the Run > Run Without Debugging button to start the server.
Note: The
launch.jsonis used for running and debugging.