Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Optimize FireDAC TFDMemTable For Low Memory Usage?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 19, 2017 11:42 PM Last Post By: Dmitry Arefiev
Eli M

Posts: 1,346
Registered: 11/9/13
Optimize FireDAC TFDMemTable For Low Memory Usage?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2017 6:54 PM
Any tips on optimizing TFDMemTable to use the least amount of memory?

I have one main TFDMemTable that has maybe 100 fields in it but only 1 record.

I also have various other sub datasets where I take a TFDMemTable and store it via the JSON save into one of the fields of the main TFDMemTable.

Some of the sub dataset TFDMemTable have blob fields of images (signatures) or memos. Generally everything works fine until I start adding a lot of the blob fields to one of the sub datasets and then my iOS device starts running low on memory.

Would switching the main TFDMemTable to be a SQLite database instead see a significant memory savings without any speed loss?

I found code in the docs (see below) that talks about optimizing for speed but I'm wondering if RecsMax at 300000 takes a lot of memory? I have it customized to RecsMax 300 or 3000 in some places where appropriate.
FDMemTable1.LogChanges := False;
FDMemTable1.FetchOptions.RecsMax := 300000; //Sample value
FDMemTable1.ResourceOptions.SilentMode := True;
FDMemTable1.UpdateOptions.LockMode := lmNone;
FDMemTable1.UpdateOptions.LockPoint := lpDeferred;
FDMemTable1.UpdateOptions.FetchGeneratorsPoint := gpImmediate;
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Optimize FireDAC TFDMemTable For Low Memory Usage?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 19, 2017 2:22 PM   in response to: Eli M in response to: Eli M
Found this function to show memory usage. So far SQLite seems like it takes more memory. Also experimenting with TClientDataSet.

function MemoryUsed: cardinal;
var
st: TMemoryManagerState;
sb: TSmallBlockTypeState;
begin
GetMemoryManagerState(st);
result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize;
for sb in st.SmallBlockTypeStates do begin
result := result + sb.UseableBlockSize * sb.AllocatedBlockCount;
end;
end;
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: Optimize FireDAC TFDMemTable For Low Memory Usage?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 19, 2017 11:42 PM   in response to: Eli M in response to: Eli M
Most of above settings does not affect on memory usage. You should use more compact field data types, for example:
* if you does not need high precision for float point numbers, then use ftFloat instead of ftFmtBcd.
* if you does not need Unicode strings, then use ftString instead of ftWideString.

Try to change the options:
* if you have string data, which may be too long, then consider to set InlineDataSize to a lower value:
http://docwiki.embarcadero.com/Libraries/Berlin/en/FireDAC.Stan.Option.TFDFormatOptions.InlineDataSize

--
With best regards,
Dmitry
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02