|
Post by Empyrion Martyr on May 7, 2008 15:24:40 GMT -5
I got a couple of questions regarding plugin dlls (mingw c++).
1) is there no other way to properly define a struct unles you
#pragma pack(push,1) struct blablabla {}; #pragma pack(pop)
? doing otherwise results in assertion failure...
2) Is there any way I can declare a pointer to a vector of structures, allocate memory to it using "new" without having to explicitly "delete[]" it inside the same DLLFUNC? In my implementations, something like
struct s1 {...}; s1* p; p = new s1,100; or however the new works in different compilers etc
will ALLWAYS crash my b4gel unless i explicitly "delete[]" the vector created inside the SAME DLLFUNC that allocated memory for it. In my dll i need the vector to be alive until i call a special Destroy() function...
any help would be appreciated.
|
|
|
Post by Tom Mulgrew on May 8, 2008 4:33:30 GMT -5
Hard to answer exactly without seeing your code, but I'll give it a shot.
1.
struct blah { int a; float b; }
Is how structs are defined in C/C++.
The #pragma stuff is necessary if you want to copy data between your C/C++ struct and a Basic4GL struc. It ensures that C/C++ doesn't decide to pad it out with empty bytes, so that when you describe your structure layout to Basic4GL (with registry.RegisterStructure(...), registry.AddStrucField(...) etc), everything lines up.
2.
If you allocate a structure with new, you don't have to delete it in the same function. You can delete it at any time later, from anywhere. You just have to remember to do so, otherwise you'll get a memory leak (it shouldn't crash though). I'm not completely sure though what you're trying to achieve here, and I wonder if you're approaching a different problem the wrong way.
Are you trying to get the data into a BASIC structure accessible from BASIC code?
|
|
|
Post by Empyrion Martyr on May 8, 2008 7:08:06 GMT -5
Thank you Tom for your answers. On point 2. I have build a linked list for an implementation of an A* algo, and some of the inner functions do the following: Create node map, resize node map, destroy node map. Thus i need to have persistent node map between calls to "Pathfind". As I can see know, some of my earlier crashes with b4gel are solved after reinstalling some drivers, and I think most of the problems are due to viruses (my McAfee crashed several times). After I properly reinstall windows my problems should be gone, although i'm almost sure most of them were caused either by viruses, or me toying with some home-cooked backdoors erasing part of my RAM memory. Thank you again Tom for your replies, I know you're a busy man. The questions I might ask about PlugIn DLL's could be answered probably by someone else who has knowledge, in order to keep you from losing precious time (I know how that feels), but i'm unsure how many on the forums have played enough with the plugin dll sdk (i know joshy did to a large extent, but mainly non-c++). See you around.
|
|