These are chat archives for ikkentim/SampSharp

5th
Jul 2015
Florian van Dillen
@fvandillen
Jul 05 2015 09:46 UTC
Holy shit that looks awesome. The delegate is used to put in arguments? (I haven't worked with delegates before)
Tim Potze
@ikkentim
Jul 05 2015 09:47 UTC
Yes
Delegates are basically a footprint the function must have to be assigned to a variable
Marco Acierno
@marcoacierno
Jul 05 2015 14:15 UTC
Seems like C++ uses RAII principe to handle memory allocation, so I think that issue #126 can be fixed doing something like this
class MonoStringToUTF8
{
public:
    char* utf8String;

    MonoStringToUTF8(MonoString *string_obj)
    {
        utf8String = mono_string_to_utf8(string_obj);
    }

    ~MonoStringToUTF8()
    {
        mono_free(utf8String);
    }
};
and then doing this when needed
MonoStringToUTF8(format_string).utf8String
Tim Potze
@ikkentim
Jul 05 2015 14:17 UTC
Just need to do g_free whenever I call it
Marco Acierno
@marcoacierno
Jul 05 2015 14:17 UTC
when you in this case return !!sampgdk::FindNative(mono_string_to_utf8(name_string));
yes but in this case return !!sampgdk::FindNative(mono_string_to_utf8(name_string));
Tim Potze
@ikkentim
Jul 05 2015 14:19 UTC
char name =mono_string_to_utf8(...); / use name... */ g_free(name);
Marco Acierno
@marcoacierno
Jul 05 2015 14:19 UTC
char* string = mono_string_to_utf8(name_string);
mono_free(string);
return !!sampgdk::FindNative(string);
oh
ok
I got it.
Tim Potze
@ikkentim
Jul 05 2015 14:19 UTC
Shouldn't free before using it
Marco Acierno
@marcoacierno
Jul 05 2015 14:20 UTC
that was my problem
I got how to do it anyway
Just because that wouldn't make sense to free it before using thats why I searched online
Marco Acierno
@marcoacierno
Jul 05 2015 15:06 UTC
visual studio says only there places with mono_string_to_utf8
rrev/SampSharp@8f50c00
Tim Potze
@ikkentim
Jul 05 2015 15:09 UTC
I guess that's true
Marco Acierno
@marcoacierno
Jul 05 2015 15:10 UTC
btw at 526 we could not allocate the utf8 if not needed (if (format_string) {allocate and put}else{put ""})
Tim Potze
@ikkentim
Jul 05 2015 22:31 UTC
Removing the direct calls to natives move than halved the size of the plugin.
This doesn't necessarily mean that stuff was improved, but it does indicate how much I have cleaned up the plugin :)
I've also created an INative interface and an INativeLoader interface. The DefaultLoader class loads the natives trough the plugin.
I made this because I'm planning to create some utilities for writing unit tests, and this utility could then simulate some natives by loading fake natives.