mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional 'nocopy' methods for List resize/reserve methods
- the size of a List often requires adjustment prior to an operation,
but old values (if any) are not of interest and will be overwritten.
In these cases can use the _nocopy versions to avoid additional memory
overhead of the intermediate list and the copy/move overhead of
retaining the old values (that we will subsequently discard anyhow).
No equivalent for PtrList/UPtrList - this would be too fragile.
- add swap DynamicField with DynamicList
BUG: fixed Dynamic{Field,List} setCapacity corner case
- for the case when the newly requested capacity coincides with the
current addressable size, the resize of the underlying list would have
been bypassed - ie, the real capacity was not actually changed.
- remove (unused) PtrDynList setCapacity method as too fragile
This commit is contained in:
3
applications/test/DynamicList2/Make/files
Normal file
3
applications/test/DynamicList2/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-DynamicList2.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-DynamicList2
|
||||
2
applications/test/DynamicList2/Make/options
Normal file
2
applications/test/DynamicList2/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
155
applications/test/DynamicList2/Test-DynamicList2.C
Normal file
155
applications/test/DynamicList2/Test-DynamicList2.C
Normal file
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Test allocation patterns when reading into an existing list.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "DynamicField.H"
|
||||
#include "IOstreams.H"
|
||||
#include "ITstream.H"
|
||||
#include "OTstream.H"
|
||||
#include "StringStream.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
#include "labelRange.H"
|
||||
#include "labelIndList.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T, int SizeMin>
|
||||
void printInfo
|
||||
(
|
||||
const word& tag,
|
||||
const DynamicList<T, SizeMin>& list,
|
||||
const bool showSize = true
|
||||
)
|
||||
{
|
||||
Info<< '<' << tag;
|
||||
if (showSize)
|
||||
{
|
||||
Info<< " size=\"" << list.size()
|
||||
<< "\" capacity=\"" << list.capacity() << "\"";
|
||||
if (list.cdata())
|
||||
{
|
||||
Info<< " ptr=\"" << name(list.cdata()) << "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " ptr=\"nullptr\"";
|
||||
}
|
||||
}
|
||||
Info<< '>' << nl << flatOutput(list) << nl
|
||||
<< "</" << tag << ">\n" << endl;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int SizeMin>
|
||||
void printInfo
|
||||
(
|
||||
const word& tag,
|
||||
const DynamicField<T, SizeMin>& list,
|
||||
const bool showSize = true
|
||||
)
|
||||
{
|
||||
Info<< '<' << tag;
|
||||
if (showSize)
|
||||
{
|
||||
Info<< " size=\"" << list.size()
|
||||
<< "\" capacity=\"" << list.capacity() << "\"";
|
||||
if (list.cdata())
|
||||
{
|
||||
Info<< " ptr=\"" << name(list.cdata()) << "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " ptr=\"nullptr\"";
|
||||
}
|
||||
}
|
||||
Info<< '>' << nl << flatOutput(list) << nl
|
||||
<< "</" << tag << ">\n" << endl;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int SizeMin>
|
||||
void readList
|
||||
(
|
||||
DynamicList<T, SizeMin>& output,
|
||||
const UList<T>& input
|
||||
)
|
||||
{
|
||||
OTstream os;
|
||||
os << input;
|
||||
ITstream is("input", os.tokens());
|
||||
|
||||
is >> output;
|
||||
}
|
||||
|
||||
template<class T, int SizeMin>
|
||||
void readList
|
||||
(
|
||||
DynamicField<T, SizeMin>& output,
|
||||
const UList<T>& input
|
||||
)
|
||||
{
|
||||
OTstream os;
|
||||
os << input;
|
||||
ITstream is("input", os.tokens());
|
||||
|
||||
is >> output;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//
|
||||
{
|
||||
DynamicList<label, 64> list1;
|
||||
|
||||
list1.resize(4);
|
||||
ListOps::identity(list1);
|
||||
|
||||
list1.resize(3);
|
||||
printInfo("", list1);
|
||||
|
||||
// list1.clear();
|
||||
// printInfo("", list1);
|
||||
|
||||
list1.setCapacity(3);
|
||||
printInfo("", list1);
|
||||
}
|
||||
|
||||
Info<< "\nEnd\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user