objectpooltest.cpp
来自「C++高级编程这本书所附的源代码」· C++ 代码 · 共 51 行
CPP
51 行
#include "ObjectPool.h"class UserRequest{public: UserRequest() {} ~UserRequest() {} // Methods to populate the request with specific information. // Methods to retrieve the request data. // (not shown) protected: // data members (not shown)};UserRequest& obtainUserRequest(ObjectPool<UserRequest>& pool){ // Obtain a UserRequest object from the pool UserRequest& request = pool.acquireObject(); // populate the request with user input // (not shown) return (request);}void processUserRequest(ObjectPool<UserRequest>& pool, UserRequest& req){ // process the request // (not shown) // return the request to the pool pool.releaseObject(req);}int main(int argc, char** argv){ ObjectPool<UserRequest> requestPool(1000); // Set up program // (not shown) while (true /* program is running */) { UserRequest& req = obtainUserRequest(requestPool); processUserRequest(requestPool, req); } return (0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?