mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Improve documentation
This commit is contained in:
parent
ab80d9a374
commit
9ad79f0c89
@ -314,7 +314,7 @@ LLwaitTokenBeginLabel:
|
||||
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
|
||||
/* Work around for very slow/old android devices, we don't expect this
|
||||
* to be necessary on newer devices. If it take unreasonably long
|
||||
* something worser is already happening elsewere amd we return anyway.
|
||||
* something worser is already happening elsewere and we return anyway.
|
||||
*/
|
||||
if( st > RsTokenService::FAILED && st < RsTokenService::COMPLETE
|
||||
&& maxWorkAroundCnt-- > 0 )
|
||||
|
@ -3,7 +3,8 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 by Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright 2012 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright 2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -21,11 +22,44 @@
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <util/stacktrace.h>
|
||||
|
||||
#include "util/stacktrace.h"
|
||||
|
||||
/**
|
||||
* @brief Shorthand macro to declare optional functions output parameters
|
||||
* To define an optional output paramether use the following syntax
|
||||
*
|
||||
\code{.cpp}
|
||||
bool myFunnyFunction(
|
||||
int mandatoryParamether,
|
||||
BigType& myOptionalOutput = RS_DEFAULT_STORAGE_PARAM(BigType) )
|
||||
\endcode
|
||||
*
|
||||
* The function caller then can call myFunnyFunction either passing
|
||||
* myOptionalOutput parameter or not.
|
||||
* @see RsGxsChannels methods for real usage examples.
|
||||
*
|
||||
* @details
|
||||
* When const references are used to pass function parameters it is easy do make
|
||||
* those params optional by defining a default value in the function
|
||||
* declaration, because a temp is accepted as default parameter in those cases.
|
||||
* It is not as simple when one want to make optional a non-const reference
|
||||
* parameter that is usually used as output, in that case as a temp is in theory
|
||||
* not acceptable.
|
||||
* Yet it is possible to overcome that limitation with the following trick:
|
||||
* If not passed as parameter the storage for the output parameter can be
|
||||
* dinamically allocated directly by the function call, to avoid leaking memory
|
||||
* on each function call the pointer to that storage is made unique so once the
|
||||
* function returns it goes out of scope and is automatically deleted.
|
||||
* About performance overhead: std::unique_ptr have very good performance and
|
||||
* modern compilers may be even able to avoid the dynamic allocation in this
|
||||
* case, any way the allocation would only happen if the parameter is not
|
||||
* passed, so any effect on performace would happen only in case where the
|
||||
* function is called without the parameter.
|
||||
*/
|
||||
#define RS_DEFAULT_STORAGE_PARAM(Type) *std::unique_ptr<Type>(new Type)
|
||||
|
||||
void *rs_malloc(size_t size) ;
|
||||
|
Loading…
Reference in New Issue
Block a user