1).make()函数用法在StrongPointer.h里.
system/core/libutils/include/utils/StrongPointer.h
class sp {template template sp sp::make(Args&&... args) {T* t = new T(std::forward(args)...);sp result;result.m_ptr = t;t->incStrong(t); // bypass check_not_on_stack for heap allocationreturn result;}
};
2).其实RefBase.h里引用了utils/StrongPointer.h,即使用了智能指针,如下位置:
system/core/libutils/include/utils/RefBase.h
#include **
```Makefile
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := sppointer
LOCAL_SRC_FILES := strong_pointer.cpp
LOCAL_SHARED_LIBRARIES := libcutils libutils
include $(BUILD_EXECUTABLE)
#include
#include
#include using namespace android;class Bigclass : public RefBase{
public:Bigclass(String8 name): mDriverName(name){printf("Bigclass::mDriverName = %s\n",mDriverName.c_str());}String8 getDriverName() {return mDriverName;}private:String8 mDriverName;
};int main(){const char *driver = "/dev/binder";static sp bC;//bC = = new Bigclass(String8(driver));//Or bC = sp::make(String8(driver));printf("xxx------> driverName = %s\n",bC->getDriverName().c_str());return 0;
}