2009-02-04
07:53 AM
- last edited on
2024-09-09
10:54 AM
by
Doreena Deng
2009-02-05 11:26 AM
2009-02-05 11:28 AM
Ranga wrote:Just for clarity, this function could be:
I want to change my project Libraries Folder in ArchiCAD 12. I am using following function.
Void setupLibrariesForAC12()
{ etc...
void setupLibrariesForAC12()
{
API_LibrariesInfo libInfo;
memset(&libInfo, 0, sizeof(API_LibrariesInfo));
libInfo.nLib = 2;
libInfo.locations = (IO::Location**) BMAllocateHandle (libInfo.nLib * sizeof(IO::Location, ALLOCATE_CLEAR, 0));
libInfo.useSatellite = false;
(*libInfo.locations)[0] = IO::Location(“C:\\Archicad12\\Archicad Library”);
(*libInfo.locations)[1] = IO::Location(“C:\\Archicad Development Library”);
ACAPI_Environment(APIEnv_SetLibrariesID, &libInfo, NULL);
BMKillHandle(reinterpret_cast<GSHandle *> (&libInfo.locations));
}
Could someone from GS comment on whether the calls to placement new and the Location destructor are necessary for some internal initialisation or cleanup?2009-02-05 11:31 AM
Oleg wrote:Yes, the Location object may have allocated resources... or may do so in future - perhaps it's also a safeguard against future changes?
The Location class may allocate some heap memory internally.
Destructor call is necessary to release it by Location.
I dont think the placement new is the reason.
A handle is not typed array, like std::vecor or C++ array and destructor will not called automatically.
2009-02-05 11:41 AM
Ralph wrote:Yes, it may have as dynamically length of string path.
Yes, the Location object may have allocated resources... or may do so in future - perhaps it's also a safeguard against future changes?
2009-02-05 11:54 AM
Oleg wrote:I agree - this is messy. I guess AC (like most mature software) has to get by with some awkward scenarios as the new is built onto the old. I've sent an email asking for clarification on this one.
Better if GS do special function like
KillLocationHandle as there is for Prams etc.
But more clear design if there will not mix C++ and C (as most struct is plain structs).
2009-02-05 04:39 PM
Ralph wrote:Yep, it does contain a few pointers, which have to be allocated correctly with a constructor call, and also does registration and un-registration as well.
I agree - this is messy. I guess AC (like most mature software) has to get by with some awkward scenarios as the new is built onto the old. I've sent an email asking for clarification on this one.
Thinking about it, you are probably right. The Location object might either allocate resources or rely on reference counting to release resources when no object refers to them. Either way, explicitly releasing the object would be essential.
2009-02-06 02:51 AM
Ralph wrote:hi Ralph,Ranga wrote:Just for clarity, this function could be:
I want to change my project Libraries Folder in ArchiCAD 12. I am using following function.
Void setupLibrariesForAC12()
{ etc...void setupLibrariesForAC12() { API_LibrariesInfo libInfo; memset(&libInfo, 0, sizeof(API_LibrariesInfo)); libInfo.nLib = 2; libInfo.locations = (IO::Location**) BMAllocateHandle (libInfo.nLib * sizeof(IO::Location, ALLOCATE_CLEAR, 0)); libInfo.useSatellite = false; (*libInfo.locations)[0] = IO::Location(“C:\\Archicad12\\Archicad Library”); (*libInfo.locations)[1] = IO::Location(“C:\\Archicad Development Library”); ACAPI_Environment(APIEnv_SetLibrariesID, &libInfo, NULL); BMKillHandle(reinterpret_cast<GSHandle *> (&libInfo.locations)); }Could someone from GS comment on whether the calls to placement new and the Location destructor are necessary for some internal initialisation or cleanup?
Ranga, are you sure the link error is connected to this function, i.e. did it link properly previously? And have you linked to the correct libraries as Oleg suggested?
2009-02-07 04:22 PM
Ranga wrote:Based on the comments from Ákos, you really do need to use placement new and the destructor. Although the amount of memory leaked will probably be quite small, it's poor practice and might bite you later.
If I am using destructor I am getting Link error and If I am not using destructor No errors and and my code working fine(it setting new library).
2009-04-12 07:46 PM
2009-04-14 05:24 AM