Comments (6)
For HashMap, yes, it is safe. The layout does not change until the loop is finished. For other types like LinkedList, Vectorb, etc. no. It is planned to support the latter though.
from mql4-lib.
Thank you!
So it is safe for HashMap but not for Map.
Is it safe for HashSet?
from mql4-lib.
It is safe for any Map derived containers (but HashMap is the only one for now) since the remove
method is defined on MapIterator. HashSet is a Collection and its Iterator does not have a remove
method. But for simple cases like Vector or Vector<SomePointer*>, you can set
a special value as a mark for removal, and then use remoeAll
method of Collection to do batch removal after the loop. In the future, a similar remove
method will be added to the Iterator class.
from mql4-lib.
Hello again,
It seems that HashSet remove() has bug.
Sometimes (randomly) remove
function did not remove key completely, but instead set key to 0.
Update: Currently, to avoid this issue I use Set
, not HashSet
Here are some logs from my test:
2018.01.29 23:00:17.161 TradeInfo (USDJPY,H1) Ticket is being checked: 2273470 on symbol USDJPY
2018.01.29 23:00:17.161 TradeInfo (USDCHF,H1) Ticket is being checked: 2273435 on symbol USDCHF
2018.01.29 23:00:17.161 TradeInfo (USDCHF,H1) Ticket is being checked: 2273487 on symbol USDCHF
2018.01.29 23:00:17.161 TradeInfo (USDCHF,H1) Ticket is being checked: 2273488 on symbol USDCHF
2018.01.29 23:00:17.161 TradeInfo (USDCHF,H1) Ticket is being checked: 2273437 on symbol USDJPY
2018.01.29 23:00:17.161 TradeInfo (USDCHF,H1) Ticket is being checked: 2273470 on symbol USDJPY
2018.01.29 23:00:17.201 TradeInfo (USDJPY,H1) Ticket is being checked: 2273435 on symbol USDCHF
2018.01.29 23:00:17.201 TradeInfo (USDJPY,H1) Ticket is being checked: 2273487 on symbol USDCHF
2018.01.29 23:00:17.201 TradeInfo (USDJPY,H1) Ticket is being checked: 2273488 on symbol USDCHF
2018.01.29 23:00:17.201 TradeInfo (USDJPY,H1) Ticket is being checked: 2273437 on symbol USDJPY
2018.01.29 23:00:17.201 TradeInfo (USDJPY,H1) Ticket is being checked: 2273470 on symbol USDJPY
2018.01.29 23:00:17.417 TradeInfo (USDCHF,H1) Ticket is removed: 2273435
2018.01.29 23:00:17.417 TradeInfo (USDCHF,H1) Ticket is being checked: 0 on symbol USDCHF
2018.01.29 23:00:17.417 TradeInfo (USDCHF,H1) invalid pointer access in 'TradeInfo.mq5' (546,13)
2018.01.29 23:00:17.417 TradeInfo (USDJPY,H1) Ticket is removed: 2273435
2018.01.29 23:00:17.417 TradeInfo (USDJPY,H1) Ticket is being checked: 0 on symbol USDCHF
My code look like this:
Tickets is HashSet<ulong>
foreachm(ulong, ticket, MyPositionInfo*, posInfo, ticketPosInfo)
{
// If Ticket is not available, it means that Position has been closed.
// Then remove the PosInfo in TicketPosInfo and delete the posInfo.
// Remove Ticket in symbolPosInfo[sym].
// If there is no ticket left, then delete and remove symbolPosInfo[sym]
if (!PositionSelectByTicket(ticket))
{
string sym = posInfo.iSymbol;
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// TICKET IS REMOVED FROM symbolPosInfo[sym].Tickets
bool result = symbolPosInfo[sym].Tickets.remove(ticket);
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
RemoveSymbolPositionsIfEmpty(sym);
MyPositionInfo::RemovePositionByTicket(ticket);
PrintFormat("Ticket is removed: %d %d", ticket, result);
}
}
//Update Calculating Profit, Volume, Position count for SymbolPositions
foreachm(string, sym, SymbolPositionsInfo*, symPosInfo, symbolPosInfo)
{
//////////////////////////////////////////////////////////////
// CHECK TICKET FROM symbolPosInfo[sym].Tickets
foreachv(ulong, ticket, symPosInfo.Tickets)
{
PrintFormat("Ticket is being checked: %d on symbol %s", ticket, sym);
MyPositionInfo * posInfo = ticketPosInfo[ticket];
......
I compare HashSet and HashMap, this is just my guess
Shall the below code from HashSet
if(m_owned)
{
// delete possble pointers
SafeDelete(m_entries.getKey(ix));
}
be:
SafeDelete(m_entries.getKey(ix));
if(m_owned)
{
// delete possble pointers
//SafeDelete(m_entries.getKey(ix));
}
from mql4-lib.
Thanks for reporting this. The m_owned
and SafeDelete
are not related to this issue since HashSet elements are not pointers. I suppose it is a bug of HashSetIterator. I submitted a commit just now and could you please pull the latest code and test to see if the problem gets fixed?
from mql4-lib.
Thank you!!
It is working great now! No error so far
from mql4-lib.
Related Issues (20)
- Save and load Vector from disk HOT 3
- New update to MT4 1210 2019.9.6, LinkedList.mqh ERROR. HOT 2
- ArrayList is mentioned in the documentation, however it's missing in the code
- Pushing to Vector or Linked list a reference cause compiler error HOT 2
- Implement "as series" for Vector
- Array out of range error while iterating over elements in the Vector HOT 1
- how to sort the LinkedList HOT 1
- "Invalid Point access" error on calling SymbolAnalyzer::getConversionSymbol of FxSymbol module HOT 1
- '=' - type mismatch GlobalVariable.mqh HOT 3
- '=' - type mismatch GlobalVariable.mqh 292 12 HOT 1
- Please update Json parse example in README file
- Json.mqh 的 parseInt 是否該做以下修正? HOT 3
- Finish Making Cross Version HOT 1
- 1
- Compilation error in 'HelloWorldServer.mq4' file HOT 2
- Can i use this libary for trade a account without EA HOT 4
- Classes in collections HOT 1
- does this lib support mac os m1 HOT 2
- LinkedList Initialization in MQL4 HOT 3
- SortedArray with custom SortComparer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mql4-lib.