Old 09-14-2017, 08:27 AM   #1
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default Are C++ safer/faster than Lua/EEL when parsing chunks?

First of all, my knowledge of C is closer to zero, so I`m sorry if I saying something totally wrong.

I though before that C++ code perform faster because it closely interract with some internal REAPER objects. Today I just for interest took a look at SWS source and find their stuff also operate almost same things I have in mind from scripter side.

Code:
bool SNM_AddTCPFXParm(MediaTrack* _tr, int _fxId, int _prmId)
{
	bool updated = false;
	if (_tr && _fxId>=0 && _prmId>=0 && _fxId<TrackFX_GetCount(_tr) && _prmId<TrackFX_GetNumParams(_tr, _fxId))
	{
		// already exists?
		int fxId, prmId;
		for (int i=0; i<CountTCPFXParms(NULL, _tr); i++)
			if (GetTCPFXParm(NULL, _tr, i, &fxId, &prmId))
				if (fxId==_fxId && prmId==_prmId)
					return false;

		SNM_ChunkParserPatcher p(_tr);

		// first get the fx chain: a straight search for the fx would fail (possible mismatch with frozen track, item fx, etc..)
		WDL_FastString chainChunk;
		if (p.GetSubChunk("FXCHAIN", 2, 0, &chainChunk, "<ITEM") > 0)
		{
			SNM_ChunkParserPatcher pfxc(&chainChunk, false);
			int pos = pfxc.Parse(SNM_GET_CHUNK_CHAR,1,"FXCHAIN","WAK",_fxId,0);
			if (pos>0)
			{
				char line[SNM_MAX_CHUNK_LINE_LENGTH] = "";
				if (_snprintfStrict(line, sizeof(line), "PARM_TCP %d\n", _prmId) > 0)
				{
					pfxc.GetChunk()->Insert(line, --pos);
					if (p.ReplaceSubChunk("FXCHAIN", 2, 0, pfxc.GetChunk()->Get(), "<ITEM")) {
						updated = true;
						p.Commit(true);
					}
				}
			}
		}
	}
	return updated;
}
This function add 'PARM_TCP param_number' line to FX chunk. As far as I can see, there is no any special access to some internal variables, but just parse chunk. If I do almost same thing (I need to set parameter alias) in Lua, will it be 'worse' (much slower, less safer) than a using extension API?
mpl is offline   Reply With Quote
Old 09-14-2017, 08:45 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by mpl View Post
will it be 'worse' (much slower, less safer) than a using extension API?
Likely not slower by much.

Regarding safety, it's probably easier to mess up stuff when dealing with C++ or especially C code. (Even the simplest operations on text strings can cause memory corruption, if not done exactly right.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 09-14-2017, 08:58 AM   #3
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

It's also worth noting that the chunk handling code above is probably quite far from optimal, but good enough
Justin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.