Re: Compile time initialization of AA
Le 23/03/2018 à 23:43, Xavier Bigand a écrit : I am trying to initialize an global immutable associative array of structs, but it doesn't compile. I am getting the following error message : "Error: not an associative array initializer". As I really need to store my data for a compile time purpose if we can't do that with AA, I'll use arrays instead. Here is my code : struct EntryPoint { string moduleName; string functionName; boolbeforeForwarding = false; } immutable EntryPoint[string] entryPoints = [ "wglDescribePixelFormat": {moduleName:"opengl32.forward_initialization", functionName:"wglDescribePixelFormat"} ]; I finally found something that works great: enum entryPoints = [ "wglChoosePixelFormat": EntryPoint("opengl32.forward_initialization", "client_wglChoosePixelFormat"), "wglDescribePixelFormat": EntryPoint("opengl32.forward_initialization", "client_wglDescribePixelFormat") ]; I am able to use this enum like an AA.
Compile time initialization of AA
I am trying to initialize an global immutable associative array of structs, but it doesn't compile. I am getting the following error message : "Error: not an associative array initializer". As I really need to store my data for a compile time purpose if we can't do that with AA, I'll use arrays instead. Here is my code : struct EntryPoint { string moduleName; string functionName; boolbeforeForwarding = false; } immutable EntryPoint[string] entryPoints = [ "wglDescribePixelFormat": {moduleName:"opengl32.forward_initialization", functionName:"wglDescribePixelFormat"} ];
Re: CTFE and -betterC
Le 16/03/2018 à 22:58, Xavier Bigand a écrit : Le 15/03/2018 à 01:09, Flamaros a écrit : On Wednesday, 14 March 2018 at 01:17:54 UTC, rikki cattermole wrote: You will still need DllMain, that is a platform requirement. I am not sure about that because when DllAnalyser don't see it in the opengl32.dll from the system32 directory. And the documentation indicate that it is optional. I finally choose to put the entry points generation in a sub-project that put them in a d file, like that it is easier to make the CTFE working and will be much better for the debugging and compilation time. So I have also some few other questions : - Is it a bug that ctRegex doesn't with the return of allMembers? - What is the status of the new CTFE engine? - Will CTFE be able to write files or expose a way to see to resulting generated code for a debug purpose? - Is there a reason why CTFE is impacted by the -betterC option? I actually found token strings, but I can't figure out how to cascade them, it is even possible? I tried things like that : enum loadSystemSymbolsCode = q{ version (Windows) { extern (Windows) void loadSytemSymbols() { import core.sys.windows.windows; immutable string dllFilePath = "C:/Windows/System32/opengl32.dll"; auto hModule = LoadLibraryEx(dllFilePath, null, 0); if (hModule == null) { return; } writeln(dllFilePath ~ " loaded."); "%SYSTEM_BINDINGS%" } } }; enum moduleCode = q{ module api_entry; import std.stdio : writeln; import derelict.util.wintypes; export extern (C) { mixin(loadSystemSymbolsCode); } }; string getLoadSystemSymbolsCode(string bindinsCode)() { return loadSystemSymbolsCode.replace("%SYSTEM_BINDINGS%", bindinsCode); } string getModuleCode(string loadSystemSymbolsCode)() { return moduleCode.replace("%LOAD_SYSTEM_SYMBOLS%", loadSystemSymbolsCode); } voidmain() { import std.stdio : File; auto file = File("../opengl32/src/api_entry.d", "w"); file.writeln( getModuleCode!( getLoadSystemSymbolsCode!("test;")()) ); } Is there some materials for learning to do this kind of things with CTFE? I feel my self little stupid, I don't need the " in the token string with the %WordToReplace%. So I think that the magic will happen.
Re: CTFE and -betterC
Le 15/03/2018 à 01:09, Flamaros a écrit : On Wednesday, 14 March 2018 at 01:17:54 UTC, rikki cattermole wrote: You will still need DllMain, that is a platform requirement. I am not sure about that because when DllAnalyser don't see it in the opengl32.dll from the system32 directory. And the documentation indicate that it is optional. I finally choose to put the entry points generation in a sub-project that put them in a d file, like that it is easier to make the CTFE working and will be much better for the debugging and compilation time. So I have also some few other questions : - Is it a bug that ctRegex doesn't with the return of allMembers? - What is the status of the new CTFE engine? - Will CTFE be able to write files or expose a way to see to resulting generated code for a debug purpose? - Is there a reason why CTFE is impacted by the -betterC option? I actually found token strings, but I can't figure out how to cascade them, it is even possible? I tried things like that : enum loadSystemSymbolsCode = q{ version (Windows) { extern (Windows) void loadSytemSymbols() { import core.sys.windows.windows; immutable string dllFilePath = "C:/Windows/System32/opengl32.dll"; auto hModule = LoadLibraryEx(dllFilePath, null, 0); if (hModule == null) { return; } writeln(dllFilePath ~ " loaded."); "%SYSTEM_BINDINGS%" } } }; enum moduleCode = q{ module api_entry; import std.stdio : writeln; import derelict.util.wintypes; export extern (C) { mixin(loadSystemSymbolsCode); } }; string getLoadSystemSymbolsCode(string bindinsCode)() { return loadSystemSymbolsCode.replace("%SYSTEM_BINDINGS%", bindinsCode); } string getModuleCode(string loadSystemSymbolsCode)() { return moduleCode.replace("%LOAD_SYSTEM_SYMBOLS%", loadSystemSymbolsCode); } voidmain() { import std.stdio : File; auto file = File("../opengl32/src/api_entry.d", "w"); file.writeln( getModuleCode!( getLoadSystemSymbolsCode!("test;")()) ); } Is there some materials for learning to do this kind of things with CTFE?
CTFE and -betterC
As I am trying to do a dll that acts exactly like one written in C, I am trying to compile my code with the -betterC option. So I would not need the DllMain function. I am not sure that I use the best syntax for my CTFE function to be able to make it works with the option -betterC and to maintain it after. In particular I have following issues (my code is at the end of message) : * startsWith function doesn't compile with -betterC * can't put static before the first foreach * don't really now how to factorize small expressions (oglFunctionName , oglFunctionName,...) * how to make the code I generate less polluted by conditions and iterations? Certainly by naming some previously computed parts with alias? * after that how to see the generated result and debug? Thank you in advance for any help. module api_entry; import std.stdio : writeln; import std.algorithm.searching; import missing_ogl; import std.traits; import std.meta; static string implementFunctionsOf(string Module, bool removeARB = false)() { import std.traits; import std.regex; import std.conv; mixin("import " ~ Module ~ ";"); string res; res ~= "extern (C) {\n"; foreach (name; __traits(allMembers, mixin(Module))) { static if (name.startsWith("da_") && mixin("isCallable!" ~ name)) { alias derelict_oglFunctionName = Alias!(name[3..$]); alias oglFunctionName = derelict_oglFunctionName; alias returnType = Alias!(ReturnType!(mixin(name)).stringof); alias parametersType = Alias!(Parameters!(mixin(name)).stringof); static if (removeARB && name.endsWith("ARB")) oglFunctionName = oglFunctionName[0..$ - 3]; res ~= "export\n" ~ returnType ~ "\n" ~ oglFunctionName ~ parametersType ~ "\n" ~ "{\n" ~ "writeln(\"" ~ oglFunctionName ~ " is not specialized\");\n"; // Forward the call to the driver (with arguments and return the // value of the forward directly) res ~= "import " ~ Module ~ ";"; // For a reason I do not understand the compiler can not // compile with returnType static if (ReturnType!(mixin(name)).stringof == "int function()") res ~= "alias extern (C) " ~ returnType ~ " returnType;\n" ~ "return cast(returnType) "; else if (returnType != "void") res ~= "return "; res ~= "" ~ Module ~ "." ~ derelict_oglFunctionName ~ "("; foreach (i, parameter; Parameters!(mixin(name))) { if (i > 0) res ~= ", "; // We use the default parameter name variable "_param_x" where x // is the index of the parameter starting from 0 res ~= "_param_" ~ to!string(i); } res ~= ");"; res ~= "}\n"; } } res ~= "}\n"; return res; } mixin(implementFunctionsOf!("derelict.opengl3.functions")); mixin(implementFunctionsOf!("derelict.opengl3.deprecatedFunctions"));
Re: How give a module to a CTFE function
Le 12/03/2018 à 23:28, Xavier Bigand a écrit : Le 12/03/2018 à 23:24, Xavier Bigand a écrit : Le 12/03/2018 à 22:30, arturg a écrit : On Monday, 12 March 2018 at 21:00:07 UTC, Xavier Bigand wrote: Hi, I have a CTFE function that I want to make more generic by given it a module as parameter. My actual code looks like : mixin(implementFunctionsOf()); string implementFunctionsOf() { import std.traits; stringres; foreach(name; __traits(allMembers, myHardCodedModule)) { } return res; } I tried many things but I can't figure out the type of the parameter I should use for the function implementFunctionsOf. you can use a alias or a string: void fun(alias mod, string mod2)() { foreach(m; __traits(allMembers, mod)) pragma(msg, m); foreach(m; __traits(allMembers, mixin(mod2))) pragma(msg, m); } void main() { import std.stdio; fun!(std.stdio, "std.stdio"); } I tried both without success, Here is my full code : module api_entry; import std.stdio : writeln; import std.algorithm.searching; import derelict.opengl3.functions; import std.traits; string implementFunctionsOf(string mod) { import std.traits; stringres; static foreach(name; __traits(allMembers, mixin(mod))) { static if (mixin("isCallable!" ~ name) && name.startsWith("da_")) { string oglFunctionName = name[3..$]; string returnType = ReturnType!(mixin(name)).stringof; string parametersType = Parameters!(mixin(name)).stringof; res ~= "export\n" ~ "extern (C)\n" ~ returnType ~ "\n" ~ oglFunctionName ~ parametersType ~ "\n" ~ "{\n" ~ " writeln(\"" ~ oglFunctionName ~ "\");\n"; static if (ReturnType!(mixin(name)).stringof != "void") { res ~= " " ~ returnType ~ " result;\n" ~ " return result;"; } res ~= "}\n"; } } return res; } mixin(implementFunctionsOf("derelict.opengl3.functions")); As string I get the following error: ..\src\api_entry.d(16): Error: variable `mod` cannot be read at compile time ..\src\api_entry.d(48):called from here: `implementFunctionsOf("derelict.opengl3.functions")` I also tried to make implementFunctionsOf a mixin template. I forgot to precise, that I don't have a main, because I am trying to create an opengl32.dll. This is why I already have a mixin to inject to function definitions in the root scope. Ok, it works with the alias, I didn't see the last () in the implementFunctionsOf prototype. Thank you a lot.
Re: How give a module to a CTFE function
Le 12/03/2018 à 23:24, Xavier Bigand a écrit : Le 12/03/2018 à 22:30, arturg a écrit : On Monday, 12 March 2018 at 21:00:07 UTC, Xavier Bigand wrote: Hi, I have a CTFE function that I want to make more generic by given it a module as parameter. My actual code looks like : mixin(implementFunctionsOf()); string implementFunctionsOf() { import std.traits; stringres; foreach(name; __traits(allMembers, myHardCodedModule)) { } return res; } I tried many things but I can't figure out the type of the parameter I should use for the function implementFunctionsOf. you can use a alias or a string: void fun(alias mod, string mod2)() { foreach(m; __traits(allMembers, mod)) pragma(msg, m); foreach(m; __traits(allMembers, mixin(mod2))) pragma(msg, m); } void main() { import std.stdio; fun!(std.stdio, "std.stdio"); } I tried both without success, Here is my full code : module api_entry; import std.stdio : writeln; import std.algorithm.searching; import derelict.opengl3.functions; import std.traits; string implementFunctionsOf(string mod) { import std.traits; stringres; static foreach(name; __traits(allMembers, mixin(mod))) { static if (mixin("isCallable!" ~ name) && name.startsWith("da_")) { string oglFunctionName = name[3..$]; string returnType = ReturnType!(mixin(name)).stringof; string parametersType = Parameters!(mixin(name)).stringof; res ~= "export\n" ~ "extern (C)\n" ~ returnType ~ "\n" ~ oglFunctionName ~ parametersType ~ "\n" ~ "{\n" ~ " writeln(\"" ~ oglFunctionName ~ "\");\n"; static if (ReturnType!(mixin(name)).stringof != "void") { res ~= " " ~ returnType ~ " result;\n" ~ " return result;"; } res ~= "}\n"; } } return res; } mixin(implementFunctionsOf("derelict.opengl3.functions")); As string I get the following error: ..\src\api_entry.d(16): Error: variable `mod` cannot be read at compile time ..\src\api_entry.d(48):called from here: `implementFunctionsOf("derelict.opengl3.functions")` I also tried to make implementFunctionsOf a mixin template. I forgot to precise, that I don't have a main, because I am trying to create an opengl32.dll. This is why I already have a mixin to inject to function definitions in the root scope.
Re: How give a module to a CTFE function
Le 12/03/2018 à 22:30, arturg a écrit : On Monday, 12 March 2018 at 21:00:07 UTC, Xavier Bigand wrote: Hi, I have a CTFE function that I want to make more generic by given it a module as parameter. My actual code looks like : mixin(implementFunctionsOf()); string implementFunctionsOf() { import std.traits; stringres; foreach(name; __traits(allMembers, myHardCodedModule)) { } return res; } I tried many things but I can't figure out the type of the parameter I should use for the function implementFunctionsOf. you can use a alias or a string: void fun(alias mod, string mod2)() { foreach(m; __traits(allMembers, mod)) pragma(msg, m); foreach(m; __traits(allMembers, mixin(mod2))) pragma(msg, m); } void main() { import std.stdio; fun!(std.stdio, "std.stdio"); } I tried both without success, Here is my full code : module api_entry; import std.stdio : writeln; import std.algorithm.searching; import derelict.opengl3.functions; import std.traits; string implementFunctionsOf(string mod) { import std.traits; string res; static foreach(name; __traits(allMembers, mixin(mod))) { static if (mixin("isCallable!" ~ name) && name.startsWith("da_")) { string oglFunctionName = name[3..$]; string returnType = ReturnType!(mixin(name)).stringof; string parametersType = Parameters!(mixin(name)).stringof; res ~= "export\n" ~ "extern (C)\n" ~ returnType ~ "\n" ~ oglFunctionName ~ parametersType ~ "\n" ~ "{\n" ~ " writeln(\"" ~ oglFunctionName ~ "\");\n"; static if (ReturnType!(mixin(name)).stringof != "void") { res ~= " " ~ returnType ~ " result;\n" ~ " return result;"; } res ~= "}\n"; } } return res; } mixin(implementFunctionsOf("derelict.opengl3.functions")); As string I get the following error: ..\src\api_entry.d(16): Error: variable `mod` cannot be read at compile time ..\src\api_entry.d(48):called from here: `implementFunctionsOf("derelict.opengl3.functions")` I also tried to make implementFunctionsOf a mixin template.
How give a module to a CTFE function
Hi, I have a CTFE function that I want to make more generic by given it a module as parameter. My actual code looks like : mixin(implementFunctionsOf()); string implementFunctionsOf() { import std.traits; string res; foreach(name; __traits(allMembers, myHardCodedModule)) { } return res; } I tried many things but I can't figure out the type of the parameter I should use for the function implementFunctionsOf.
Re: Need help to compile code with traits
Le 05/02/2017 à 18:32, Basile B. a écrit : On Sunday, 5 February 2017 at 14:59:04 UTC, Xavier Bigand wrote: Hi, I am trying to create an allocator that don't use the GC, and I have issues for the initialization of member before calling the constructor. Here is my actual code : mixin template NogcAllocator(T) { static TnogcNew(T, Args...)(Args args) @nogc { import core.stdc.stdlib : malloc; import std.traits; Tinstance; instance = cast(T)malloc(__traits(classInstanceSize, T)); foreach (string member; __traits(allMembers, T)) { static if (isType!(__traits(getMember, T, member))) __traits(getMember, instance, member) = typeof(__traits(getMember, T, member)).init; } instance.__ctor(args); return instance; } static voidnogcDelete(T)(T instance) @nogc { import core.stdc.stdlib : free; instance.__dtor(); free(instance); } } unittest { struct Dummy { int field1 = 10; int field2 = 11; } class MyClass { mixin NogcAllocator!MyClass; int a = 0; int[] b = [1, 2, 3]; Dummy c = Dummy(4, 5); int d = 6; this() @nogc { } this(int val) @nogc { d = val; } } MyClass first = MyClass.nogcNew!MyClass(); MyClass second = MyClass.nogcNew!MyClass(7); assert(first.a == 0); assert(first.b == [1, 2, 3]); assert(first.c.field1 == 4); assert(first.d == 6); assert(second.c.field1 == 4); assert(second.d == 7); } And the compilation errors : ..\src\core\nogc_memory.d(16): Error: no property 'this' for type 'core.nogc_memory.__unittestL39_3.MyClass' ..\src\core\nogc_memory.d(17): Error: type Monitor is not an expression ..\src\core\nogc_memory.d(63): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass) error instantiating ..\src\core\nogc_memory.d(16): Error: no property 'this' for type 'core.nogc_memory.__unittestL39_3.MyClass' ..\src\core\nogc_memory.d(17): Error: type Monitor is not an expression ..\src\core\nogc_memory.d(64): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass, int) error instantiating I don't understand my mistake with the getMember and isType traits. And I am curious about of what is the Monitor. The whole thing you do to initialize could be replaced by a copy of the initializer, which is what emplace does: static T nogcNew(T, Args...)(Args args) @nogc { import core.stdc.stdlib : malloc; import std.traits, std.meta; Tinstance; enum s = __traits(classInstanceSize, T); instance = cast(T) malloc(s); (cast(void*) instance)[0..s] = typeid(T).initializer[]; instance.__ctor(args); return instance; } Nice, thank you for that, it is much elegant ;-) Your nogcDelete() is bug-prone & leaky Certainly I didn't think a lot about it for the moment. - use _xdtor, which also calls the __dtor injected by mixin. - even if you do so, __xdtors are not inherited !! instead dtor in parent classes are called by destroy() directly. Currently what I do to simulate inherited destructor is to mix this for each new generation. mixin template inheritedDtor() { private: import std.traits: BaseClassesTuple; alias B = BaseClassesTuple!(typeof(this)); enum hasDtor = __traits(hasMember, typeof(this), "__dtor"); static if (hasDtor && !__traits(isSame, __traits(parent, typeof(this).__dtor), typeof(this))) enum inDtor = true; else enum inDtor = false; public void callInheritedDtor(classT = typeof(this))() { import std.meta: aliasSeqOf; import std.range: iota; foreach(i; aliasSeqOf!(iota(0, B.length))) static if (__traits(hasMember, B[i], "__xdtor")) { mixin("this." ~ B[i].stringof ~ ".__xdtor;"); break; } } static if (!hasDtor || inDtor) public ~this() {callInheritedDtor();} } When a dtor is implemented it has to call "callInheritedDtor()" at end of the dtor implementation. Thank you a lot for this great help.
Need help to compile code with traits
Hi, I am trying to create an allocator that don't use the GC, and I have issues for the initialization of member before calling the constructor. Here is my actual code : mixin template NogcAllocator(T) { static TnogcNew(T, Args...)(Args args) @nogc { import core.stdc.stdlib : malloc; import std.traits; T instance; instance = cast(T)malloc(__traits(classInstanceSize, T)); foreach (string member; __traits(allMembers, T)) { static if (isType!(__traits(getMember, T, member))) __traits(getMember, instance, member) = typeof(__traits(getMember, T, member)).init; } instance.__ctor(args); return instance; } static void nogcDelete(T)(T instance) @nogc { import core.stdc.stdlib : free; instance.__dtor(); free(instance); } } unittest { struct Dummy { int field1 = 10; int field2 = 11; } class MyClass { mixin NogcAllocator!MyClass; int a = 0; int[] b = [1, 2, 3]; Dummy c = Dummy(4, 5); int d = 6; this() @nogc { } this(int val) @nogc { d = val; } } MyClass first = MyClass.nogcNew!MyClass(); MyClass second = MyClass.nogcNew!MyClass(7); assert(first.a == 0); assert(first.b == [1, 2, 3]); assert(first.c.field1 == 4); assert(first.d == 6); assert(second.c.field1 == 4); assert(second.d == 7); } And the compilation errors : ..\src\core\nogc_memory.d(16): Error: no property 'this' for type 'core.nogc_memory.__unittestL39_3.MyClass' ..\src\core\nogc_memory.d(17): Error: type Monitor is not an expression ..\src\core\nogc_memory.d(63): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass) error instantiating ..\src\core\nogc_memory.d(16): Error: no property 'this' for type 'core.nogc_memory.__unittestL39_3.MyClass' ..\src\core\nogc_memory.d(17): Error: type Monitor is not an expression ..\src\core\nogc_memory.d(64): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass, int) error instantiating I don't understand my mistake with the getMember and isType traits. And I am curious about of what is the Monitor.
Re: @nogc and opengl errors check
Le 21/01/2017 à 13:24, Jerry a écrit : On Friday, 20 January 2017 at 22:47:17 UTC, Xavier Bigand wrote: Hi, I am writing some code with opengl commands that I want to check in debug, so I am using the function checkgl (from glamour lib). The issue is that checkgl throw exception and can't be @nogc, I had try to use std.experimental.logger in place of exceptions, but it doesn't work either. I mostly want to be able to check the opengl errors only in debug in a way that can make the debugger breaks. On an other part as I will certainly have to log some events (even in release) I would appreciate that the logger be able to be used in @nogc functions, maybe with allocators? Don't use checkgl, it just bloats you code and there's an actual debug feature in OpenGL now. It provides more information than just an enum as well. So when a function has multiple errors that use the same enum, you can actually know what the error was rather than guessing. https://www.khronos.org/opengl/wiki/Debug_Output I had never use these API as it is doesn't work on older devices, but I'll may try to use it when available instead of glGetError. Thank you to remember me these API.
@nogc and opengl errors check
Hi, I am writing some code with opengl commands that I want to check in debug, so I am using the function checkgl (from glamour lib). The issue is that checkgl throw exception and can't be @nogc, I had try to use std.experimental.logger in place of exceptions, but it doesn't work either. I mostly want to be able to check the opengl errors only in debug in a way that can make the debugger breaks. On an other part as I will certainly have to log some events (even in release) I would appreciate that the logger be able to be used in @nogc functions, maybe with allocators?
Re: Dynamic arrays with static initialization and maybe a bug with sizeof
Le 13/12/2016 23:44, Johan Engelen a écrit : On Tuesday, 13 December 2016 at 21:27:57 UTC, Xavier Bigand wrote: Hi, I have the following code snippet : voidset() { GLfloat[]data = [ -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, ]; glBindVertexArray(mVAO); glBufferData(GL_ARRAY_BUFFER, data.sizeof, cast(void*)data, GL_STATIC_DRAW); } And I ask my self about the memory management of data, as my data array is statically initialized is it allocated on stack? Note that if you can define the data array as immutable, you save on heap memory allocation + copying (LDC, from -O0): https://godbolt.org/g/CNrZR7 -Johan Thank you for the tips.
Using Nsight with VisualD
Hi, I am trying to use Nsight with VisualD by it tell me that it can not start the program "". It seems that it does not use the right property of the project to retrieve the path of my generated binary. I do not know if it is an issue of VisualD directly or DUB that don't correctly generate the VisualD project and miss to fill a field. Does someone use Nsight and VisualD?
Re: Dynamic arrays with static initialization and maybe a bug with sizeof
Le 13/12/2016 22:39, ag0aep6g a écrit : On 12/13/2016 10:27 PM, Xavier Bigand wrote: voidset() { GLfloat[]data = [ -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, ]; glBindVertexArray(mVAO); glBufferData(GL_ARRAY_BUFFER, data.sizeof, cast(void*)data, GL_STATIC_DRAW); } And I ask my self about the memory management of data, as my data array is statically initialized is it allocated on stack? data is a function-local variable, so there is no static initialization going on. The array is allocated on the heap at run-time. On another side I have a strange behavior with the sizeof that returns 8 and not 36 (9 * 4) as I am expecting. sizeof returns the size of the dynamic array "struct", which is a pointer and a length. Instead of sizeof, use .length and multiply with the element type's .sizeof: data.length * GLfloat.sizeof Seems logic, I just read the wrong table on the documentation because there is properties static and dynamic arrays are contiguous. Thanks you
Dynamic arrays with static initialization and maybe a bug with sizeof
Hi, I have the following code snippet : voidset() { GLfloat[] data = [ -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, ]; glBindVertexArray(mVAO); glBufferData(GL_ARRAY_BUFFER, data.sizeof, cast(void*)data, GL_STATIC_DRAW); } And I ask my self about the memory management of data, as my data array is statically initialized is it allocated on stack? On another side I have a strange behavior with the sizeof that returns 8 and not 36 (9 * 4) as I am expecting.
Question about DUB
Hi, I am using DUB with the SDL language and I have two questions: 1. How can I add some text file to my project? I want to add shaders in my Visual Project. 2. How to make a compiler option depending on the platform and debug mode at the same time? Thanks.
Memory usage of dmd
I develop a web site with vibe, but because I am using a Virtual Private Server I get some memory issues. The server only has 1Go of memory ( 900Mo free) and it seems I can't compile directly on it a simple static page (70 lines). I get the following message when building with dub : Running dmd... FAIL ../../../.dub/packages/vibe-d-master/.dub/build/libevent-release-linux.posix-x86_64-dmd_2066-EB47C82EE359A00A02828E314FCE5409/ vibe-d staticLibrary Error executing command build: Orphan format specifier: %%s failed with exit code %s. This may indicate that the process has run out of memory. So for the moment I build the web site on a physical machine, and I saw the compilation takes around 1.6Go of memory. Is there some options can help me to reduce the memory consumption? As it's for production purpose I don't think that is a good idea to remove compiler optimizations. Are gdc or ldc better in this case?
Re: Memory usage of dmd
Le 10/11/2014 17:41, Etienne a écrit : On 2014-11-10 11:32 AM, Xavier Bigand wrote: Is there some options can help me to reduce the memory consumption? As it's for production purpose I don't think that is a good idea to remove compiler optimizations. The memory issues are probably related to diet templates. Yes I think it too. LDC and GDC won't help. You should definitely work and build on a machine with 4GB of ram. The server application could use as low as 8mb of ram, but compiling requires a workstation. Perhaps renting an amazon instance a few minutes for compilation would be a better idea? I already have a computer with a linux to build it, so amazon won't improve situation. As I know to be able to have no down time with vibe we need to be able to build directly on the server where the program runs. Maybe I just need to wait that I have some users to pay a better server with more memory.
Re: Memory usage of dmd
Le 10/11/2014 18:17, Etienne a écrit : On 2014-11-10 12:02 PM, Xavier Bigand wrote: As I know to be able to have no down time with vibe we need to be able to build directly on the server where the program runs. Maybe I just need to wait that I have some users to pay a better server with more memory. With a low number of users, there's no reason to worry about a 1 second downtime from closing the process and replacing the application file. You should use a bash script to keep the process open though: # monitor.sh nohup ./autostart.sh stdout.log 2 crash.log /dev/null # autostart.sh while true ; do if ! pgrep -f '{processname}' /dev/null ; then sh /home/{mysitefolder}/start.sh fi sleep 1 done # start.sh nohup ./{yourapplication} --uid={user} --gid={group} stdout.log 2 crash.log stdout.log # install.sh pkill -f '{processname}' /bin/cp -rf {yourapplication} /home/{mysitefolder}/ Using a console, run monitor.sh and the autostart.sh script will re-launch your server through start.sh into a daemon. Verifications will be made every second to ensure your server is never down because of a badly placed assert. If you need to replace your server application with an update, run the install.sh script from the folder where the update is. Thank you for tips. I'll start from your scripts.
Is it normal that unittests of phobos are executed with my project build?
I get a failure on a test in format.d when I build my own project with unittest. I though importing phobos header would not regenerate their unittest modules. Any idea of what can cause this issue? I already have reinstalled dmd with visualD completely.
Re: Working on a library: request for code review
Le 12/06/2014 20:09, Rene Zwanenburg a écrit : On Thursday, 12 June 2014 at 15:46:12 UTC, Mike wrote: On Thursday, 12 June 2014 at 00:20:28 UTC, cal wrote: Might it be worth stitching things together into a proper image processing package? Well I started working on TGA because I was disappointed that no image abstraction is present in Phobos. Go has some imaging APIs and I think D would benefit from having one too (out of the box). Would I work on std.image? Sure. Best, Mike I'm looking over your code ATM but I'd like to reply to this first. IMO it's not a good idea to create something like std.image. The std lib should ideally never have breaking changes, so it's easy to get stuck with a sub optimal API or become increasingly hard to maintain. We have Dub. Better keep the std lib lean and maintainable. If you're looking to create an awesome idiomatic D image library you're probably better of building it on top of derelict-devil or derelict-freeimage, then publish it on code.dlang.org The discoverability of good code.dlang.org projects is still limited. Some kind of rating or like system would be useful, but that's another discussion. I think it can be a great advantage to have some things like image management in phobos, cause often dub projects are big and users don't want necessary a complete multimedia library but just small pieces that are standard. For example a GUI library, will allow image manipulations, but not only, and extracting only the image modules can be hard. That the case of our DQuick project. For a project like DQuick, I would be happy to find things like images, geometric algebra,environment analysis,... in phobos. This will allow use to be focused on other things making an UI framework (Windows, events, rendering, resource management,...). Having such minimalistic APIs would be a great benefit IMO, maybe in this case some extending libraries would appear in dub.
Re: Working on a library: request for code review
Le 12/06/2014 20:35, Xavier Bigand a écrit : Le 12/06/2014 20:09, Rene Zwanenburg a écrit : On Thursday, 12 June 2014 at 15:46:12 UTC, Mike wrote: On Thursday, 12 June 2014 at 00:20:28 UTC, cal wrote: Might it be worth stitching things together into a proper image processing package? Well I started working on TGA because I was disappointed that no image abstraction is present in Phobos. Go has some imaging APIs and I think D would benefit from having one too (out of the box). Would I work on std.image? Sure. Best, Mike I'm looking over your code ATM but I'd like to reply to this first. IMO it's not a good idea to create something like std.image. The std lib should ideally never have breaking changes, so it's easy to get stuck with a sub optimal API or become increasingly hard to maintain. We have Dub. Better keep the std lib lean and maintainable. If you're looking to create an awesome idiomatic D image library you're probably better of building it on top of derelict-devil or derelict-freeimage, then publish it on code.dlang.org The discoverability of good code.dlang.org projects is still limited. Some kind of rating or like system would be useful, but that's another discussion. I think it can be a great advantage to have some things like image management in phobos, cause often dub projects are big and users don't want necessary a complete multimedia library but just small pieces that are standard. For example a GUI library, will allow image manipulations, but not only, and extracting only the image modules can be hard. That the case of our DQuick project. For a project like DQuick, I would be happy to find things like images, geometric algebra,environment analysis,... in phobos. This will allow use to be focused on other things making an UI framework (Windows, events, rendering, resource management,...). Having such minimalistic APIs would be a great benefit IMO, maybe in this case some extending libraries would appear in dub. I am thinking an other benefit is what you see as a default, the assurance of D standard conformances (portability, safety, quality, support,...).