mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	To manage an object: ```cpp // Before MyClass* ptr = new MyClass(); SrsAutoFree(MyClass, ptr); ptr->do_something(); // Now SrsUniquePtr<MyClass> ptr(new MyClass()); ptr->do_something(); ``` To manage an array of objects: ```cpp // Before char* ptr = new char[10]; SrsAutoFreeA(char, ptr); ptr[0] = 0xf; // Now SrsUniquePtr<char[]> ptr(new char[10]); ptr[0] = 0xf; ``` In fact, SrsUniquePtr is a limited subset of SrsAutoFree, mainly managing pointers and arrays. SrsUniquePtr is better than SrsAutoFree because it has the same API to standard unique ptr. ```cpp SrsUniquePtr<MyClass> ptr(new MyClass()); ptr->do_something(); MyClass* p = ptr.get(); ``` SrsAutoFree actually uses a pointer to a pointer, so it can be set to NULL, allowing the pointer's value to be changed later (this usage is different from SrsUniquePtr). ```cpp // OK to free ptr correctly. MyClass* ptr; SrsAutoFree(MyClass, ptr); ptr = new MyClass(); // Crash because ptr is an invalid pointer. MyClass* ptr; SrsUniquePtr<MyClass> ptr(ptr); ptr = new MyClass(); ``` Additionally, SrsAutoFreeH can use specific release functions, which SrsUniquePtr does not support. --------- Co-authored-by: Jacob Su <suzp1984@gmail.com>
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| if [[ ! -d 3rdparty/signaling || ! -d 3rdparty/httpx-static || ! -d 3rdparty/srs-bench ]]; then
 | |
|   echo "no signaling or httpx-static or srs-bench in $(pwd)"
 | |
|   exit -1
 | |
| fi
 | |
| if [[ ! -d ~/git/signaling || ! -d ~/git/go-oryx/httpx-static || ! -d ~/git/srs-bench ]]; then
 | |
|   echo "no signaling or httpx-static or srs-bench at ~/git"
 | |
|   exit -1
 | |
| fi
 | |
| 
 | |
| if [[ ! -f ~/git/srs-bench/go.mod ]]; then
 | |
|   echo "no feature/rtc in srs-bench"
 | |
|   exit -1
 | |
| fi
 | |
| 
 | |
| if [[ ! -d ~/git/state-threads ]]; then
 | |
|   echo "no state-threads at ~/git"
 | |
|   exit -1
 | |
| fi
 | |
| 
 | |
| echo "Copy signaling"
 | |
| cp -R 3rdparty/signaling/* ~/git/signaling/ &&
 | |
| cp -R 3rdparty/signaling/.gitignore ~/git/signaling/ &&
 | |
| (cd ~/git/signaling && git status)
 | |
| 
 | |
| echo "Copy httpx-static"
 | |
| cp -R 3rdparty/httpx-static/* ~/git/go-oryx/httpx-static/ &&
 | |
| cp -R 3rdparty/httpx-static/.gitignore ~/git/go-oryx/httpx-static/ &&
 | |
| (cd ~/git/go-oryx && git status)
 | |
| 
 | |
| echo "Copy srs-bench"
 | |
| cp -R 3rdparty/srs-bench/* ~/git/srs-bench/ &&
 | |
| cp -R 3rdparty/srs-bench/.gitignore ~/git/srs-bench/ &&
 | |
| (cd ~/git/srs-bench && git status)
 | |
| 
 | |
| echo "Copy state-threads"
 | |
| cp -R 3rdparty/st-srs/* ~/git/state-threads/ &&
 | |
| (cd ~/git/state-threads && git st)
 |