Click here to Skip to main content
15,877,051 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to get a string as input ? Pin
Sampath5799-Mar-18 20:15
Sampath5799-Mar-18 20:15 
QuestionRe: how to get a string as input ? Pin
David Crow10-Mar-18 11:07
David Crow10-Mar-18 11:07 
AnswerRe: how to get a string as input ? Pin
Tarun Jha15-Mar-18 7:50
Tarun Jha15-Mar-18 7:50 
QuestionHow can I minimize memory usage in my table-based statemachine with several hundred states? Pin
arnold_w9-Mar-18 9:02
arnold_w9-Mar-18 9:02 
GeneralRe: How can I minimize memory usage in my table-based statemachine with several hundred states? Pin
harold aptroot9-Mar-18 9:54
harold aptroot9-Mar-18 9:54 
GeneralRe: How can I minimize memory usage in my table-based statemachine with several hundred states? Pin
arnold_w9-Mar-18 10:00
arnold_w9-Mar-18 10:00 
GeneralRe: How can I minimize memory usage in my table-based statemachine with several hundred states? Pin
harold aptroot9-Mar-18 10:14
harold aptroot9-Mar-18 10:14 
AnswerRe: How can I minimize memory usage in my table-based statemachine with several hundred states? Pin
leon de boer9-Mar-18 15:16
leon de boer9-Mar-18 15:16 
You can tighten the structure at the cost of a carry an action size count. However it does allow you to use the same actions blocks for multiple states. That may often happen in that you just have things like confirm yes/no actions.

I also changed your pointer definitions to const as you are clearly going to have static tables and it will save compiler type casting errors.

I assume you are going to do this .. see the C11 initializers at code end which uses the standard _countof to autosize the arrays.
on GCC it's ARRAY_SIZE() but I hate the name so always define it _countof same as MSVC because it reflects better what it is IMHO.
typedef bool (*returnTrueOrFalseFunctionPtr) (void);
typedef void (*actionFunctionPtr) (int);

struct myAction_s {
	const actionFunctionPtr actionToPerformInThisState;
	const uint32_t actionArgument;
};

struct myStruct_s {
	returnTrueOrFalseFunctionPtr   trueOrFalse;
	const struct myStruct_s*       whereToGoIfTrue;
	const struct myStruct_s*       whereToGoIfFalse;
	const uint8_t				   maxActionsInThisState;    // Count of the actions in this state
	const struct myAction_s*	   actionsListInThisState;   // The action block pointer
 };

static void SomeYesFunc (int) {

}

static void SomeNoFunc(int) {

}

static void SomePerhapsFunc(int) {

}

static bool truefalseFunc(void) {
	return true;
}

/* ACTION BLOCK DEFINITIONS */
const struct myAction_s yesNoBlock[2] = { &SomeYesFunc, 1 , &SomeNoFunc, 2 };
const struct myAction_s yesNoPerhapsBlock[3] = { &SomeYesFunc, 1 , &SomeNoFunc, 2, &SomePerhapsFunc, 3};

/* ACTION STATE DEFINITIONS */
const struct myStruct_s nullState = { 0, 0, 0, 0, 0};
const struct myStruct_s yesNoState = { &truefalseFunc, &nullState , &nullState, _countof(yesNoBlock), &yesNoBlock[0] };
const struct myStruct_s yesNoPerhapsState = { &truefalseFunc, &nullState , &nullState, _countof(yesNoPerhapsBlock), &yesNoPerhapsBlock[0] };

In vino veritas


modified 9-Mar-18 21:53pm.

QuestionHow to get object of a view which is created using AddView(). Pin
Sampath5799-Mar-18 0:38
Sampath5799-Mar-18 0:38 
AnswerRe: How to get object of a view which is created using AddView(). Pin
Victor Nijegorodov9-Mar-18 1:45
Victor Nijegorodov9-Mar-18 1:45 
GeneralRe: How to get object of a view which is created using AddView(). Pin
Sampath57910-Mar-18 23:20
Sampath57910-Mar-18 23:20 
GeneralRe: How to get object of a view which is created using AddView(). Pin
Victor Nijegorodov11-Mar-18 2:05
Victor Nijegorodov11-Mar-18 2:05 
AnswerRe: How to get object of a view which is created using AddView(). Pin
Richard MacCutchan9-Mar-18 5:18
mveRichard MacCutchan9-Mar-18 5:18 
GeneralRe: How to get object of a view which is created using AddView(). Pin
Sampath57911-Mar-18 6:04
Sampath57911-Mar-18 6:04 
GeneralRe: How to get object of a view which is created using AddView(). Pin
Victor Nijegorodov11-Mar-18 7:12
Victor Nijegorodov11-Mar-18 7:12 
GeneralRe: How to get object of a view which is created using AddView(). Pin
Richard MacCutchan11-Mar-18 22:32
mveRichard MacCutchan11-Mar-18 22:32 
QuestionHow to release IDispatch memory. Pin
Sampath5797-Mar-18 2:45
Sampath5797-Mar-18 2:45 
AnswerRe: How to release IDispatch memory. Pin
Jochen Arndt7-Mar-18 3:10
professionalJochen Arndt7-Mar-18 3:10 
GeneralRe: How to release IDispatch memory. Pin
Sampath5798-Mar-18 18:40
Sampath5798-Mar-18 18:40 
GeneralRe: How to release IDispatch memory. Pin
Jochen Arndt8-Mar-18 21:21
professionalJochen Arndt8-Mar-18 21:21 
GeneralRe: How to release IDispatch memory. Pin
Sampath5798-Mar-18 22:27
Sampath5798-Mar-18 22:27 
GeneralRe: How to release IDispatch memory. Pin
Jochen Arndt8-Mar-18 22:55
professionalJochen Arndt8-Mar-18 22:55 
AnswerRe: How to release IDispatch memory. Pin
Randor 7-Mar-18 5:38
professional Randor 7-Mar-18 5:38 
Questionserializing an std::chrono::duration object with Boost Pin
Alexander Kindel7-Mar-18 2:12
Alexander Kindel7-Mar-18 2:12 
AnswerRe: serializing an std::chrono::duration object with Boost Pin
Alexander Kindel7-Mar-18 3:53
Alexander Kindel7-Mar-18 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.