• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

108 Neutral

About DarkRadeon

  • Rank
  1. [quote name='Washu' timestamp='1331331219' post='4920776'] [code] int* p = new int(); int q = (int)p; //truncates on any case where sizeof(q) != sizeof(p) size_t r = (size_t)p; //does not truncate. [/code] [/quote] thx u now everything is clear... I belived there was some strange behaviours with the pointer arithmetic... but the reality is more trivial than what I thought
  2. Here we are: [url="http://msdn.microsoft.com/en-us/library/3b2e7499.aspx"]http://msdn.microsof...y/3b2e7499.aspx[/url] [quote] When you use Visual C++ to create applications to run on a 64-bit Windows operating system, you should be aware of the following issues: An int and a long are 32-bit values on 64-bit Windows operating systems. For programs that you plan to compile for 64-bit platforms, you should be careful not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable. [/quote] OK, I know I'm not a genius... but is that sentence right? Here's a simple code to test that (sorry for the end ): [CODE] #include <iostream> int main( ) { int i [ 4 ] = { 1, 2 ,3 ,4 }; long l [ 4 ] = { 11, 22 ,33 ,44 }; long long ll [ 44 ] = { 111, 222 ,333 ,444 }; void* p = NULL; p = &i; std::cout << "p = &i" << std::endl; std::cout << "p = " << p << std::endl; std::cout << "&p = " << &p << std::endl; for( int i = 0; i < 4; i++ ) { std::cout << "*( p + " << i << " ) = " << *( static_cast< int* >( p ) + i ) << std::endl; } std::cout << std::endl; p = &l; std::cout << "p = &l" << std::endl; std::cout << "p = " << p << std::endl; std::cout << "&p = " << &p << std::endl; for( int i = 0; i < 4; i++ ) { std::cout << "*( p + " << i << " ) = " << *( static_cast< long* >( p ) + i ) << std::endl; } std::cout << std::endl; p = &ll; std::cout << "p = &ll" << std::endl; std::cout << "p = " << p << std::endl; std::cout << "&p = " << &p << std::endl; for( int i = 0; i < 4; i++ ) { std::cout << "*( p + " << i << " ) = " << *( static_cast< long long* >( p ) + i ) << std::endl; } std::cout << std::endl; char ch = '\n'; std::cin >> ch; return( 0 ); } [/CODE] Here is the output: [attachment=7623:asd.PNG] Everything seems to works fine... so.. Where is the truncation?
  3. [quote name='Washu' timestamp='1330555400' post='4917995'] Don't allocate large arrays on the stack. It's not designed for that. Use the heap. new/delete. std::vector<T>, std::array<T>, or similar. [/quote] Yes, I know that, but the source files were not written by me, I tested only the "cost" of the algorithm the had... [quote name='mhagain' timestamp='1330601748' post='4918135'] Regarding the heap option, it's important to actually read the documentation here otherwise you have a strong risk of getting some serious misunderstandings about Windows. This is particularly the case if coming from a background of another OS - there is sometimes no direct one-to-one mapping and if you rely on what looks or seems similar you can often go down an entirely wrong path. In this case the relevant MSDN page is here: [url="http://msdn.microsoft.com/en-us/library/ms810603.aspx"]http://msdn.microsof...y/ms810603.aspx[/url] Note that for the heap, the size specifies [i]initial[/i] reserve and commit sizes, not absolute limits: [quote]... values specifying the amount of reserved and committed space initially needed by the application.[/quote] [/quote] Thank you for the link : D. The code was written for different linux machines (servers and a distribute net), so probably the author did not care about windows memory model... Now it's all clear : ) Thank you guys.
  4. mmm OK, now I understand that the stack reserve size is expressed in byte and not int MB... now with the correct value it works perfectly..
  5. [quote name='Antheus' timestamp='1330547433' post='4917937'] Stack is limited to avoid resource exhaustion by OS. Stack is non-pageable memory and applications could exhaust RAM too quickly. [/quote] I know that but the applications I tested never had big allocation memory (topically 10-100MB) [quote name='Antheus' timestamp='1330547433' post='4917937'] Huh? Heap isn't limited beyond what OS can allocate. It's definitely not limited to 1MB. Large allocations (1GB+) however may fail, but that's not unique to Windows. [/quote] In visual studio, on the linker option there are bot Stack and Heap reserve Size, both are set to 1MB as default. [quote name='Antheus' timestamp='1330547433' post='4917937'] Unless you manually specific stack size on other platforms, the limitations are the same. it's also perfectly possible to simply smash the stack without crashing, so not having problems elsewhere might be just usual undefined behavior.[/quote] I also worked with some linux server, where I couldn't touch nothing except submitting source code, the server had the task to compile it and run it sending to me result like time execution time compilation etc.. [quote name='Antheus' timestamp='1330547433' post='4917937'] I'm guessing it has to do with something else, similar to this:[code] int bar[1024*1024*1024]; int main() { int foo[1024*1024*1024]; }[/code] bar may get allocated inside one of exe sections, so size constraints again become a problem. Not sure if and what kind of limits there are. foo is obviously too large for stack. [/quote] The biggest single "object" I had in the various programs were arrays of on million integers, like int a[ 1000000 ] and on both windows and linux an int should be 4 bytes, so 4 millions bytes, ~3.8MB, not a big problem for machines equipped with at least 4GB RAM.. [quote name='Antheus' timestamp='1330547433' post='4917937'] Application like that would require 1GB of physical RAM and 2GB of address space at minimum which is problematic in general case, but not necessarily impossible to achieve, just takes a few linker switches. Other OSes have same constraints. [/quote] I'm actually abstain from C++, but I notice that making global or static those array solve that kind of problem... Maybe I should see again the C++ memory allocation model xD
  6. [quote name='fastcall22' timestamp='1330544174' post='4917912'] [quote name='Alessio89' timestamp='1330539443' post='4917874'] getting crash on Windows for unknown reason [/quote] Were you not debugging? If you were, you would have received a "Stack Overflow" exception... [/quote] because I used different IDEs and compilers I was "testing" on many machines.. and only on Windows PCs I had that problem and I knew that the code was right, so I didn't think about debugging..
  7. Yes, I only learn it today, after an entire afternoon spent with several algorithms and data structures C++ samples getting crash on Windows for unknown reason -.- One answer could be: "for optimization kinda stuffs..." ... I mean, are you kidding me Microsoft? Why don't you give me a simple message like "Hey you dumb-ass, here you cannot allocate more then 1MiB onto stack or you must change the linker option"? On several linux machines all worked fine, even with very large stack allocations (more than 100MB), so what is the real reason? I know that generally having a really big stack is not so common (an a good idea), but why Microsoft set a lot of limitation without warning the user? ç___ç edit: wow, same limitation for the heap :|
  8. Frank Luna - DirectX 9.0 A Shader Approach

    starting to vs 2010 you should manually link the dxsdk library to the linker in the project proprieties... or manually editing the MSbuild profile.. fortunately the next DXSDK should be a part of the next windows sdk, so this problem will solved..
  9. mmm OK, but this should avoid the need of VC++ redistributable for the end user.. I hope that with VC++12 MS will finally bring standard Unicode support (VC++11 will not support it .-. )
  10. Not sure how to get into C++

    you can also download Bruce Eckels free electronic version of thinking in c++ 2nd edition, vol1 and vol2: [url="http://www.mindviewinc.com/Books/downloads.html"]http://www.mindviewinc.com/Books/downloads.html[/url]
  11. Not sure how to get into C++

    C++ is no more an "extension" of C. It was... 20 yeas ago or when it comes out for the first time. Just because with C++ you can write some procedural code that a C compiler can read (with some few restrictions) it doesn't mean C++ is a superset of C language. Today they are two different languages. Personally I think that ISO should break C compatibility but this is just mine thought and another story...
  12. [quote name='Martins Mozeiko' timestamp='1325808356' post='4900174'] There is int _wremove(const wchar_t* path) function in <stdio.h> [/quote]tnx
  13. Tnx I will continue to use DeleteFileW of Windows.h..
  14. I must delete a file with an Unicode name. The file-name is stored in a [b]w[/b]string. Is there a way to do it without using windows api? std::remove( ) of cstdio library doesn't work with wchar_t...
  15. Avoiding polymorphism in Java

    [quote name='ManaStone' timestamp='1325712893' post='4899709'] Is there a way I can explicitly avoid polymorphism is Java? For example, in the following code: [CODE] public class Main { public static void main(String[] args) { new Main().Run(); } public void Run() { ClassB b = new ClassB(); b.doThing(); } public class ClassA { public void doThing() { print(); } public void print() { System.out.println("A"); } } class ClassB extends ClassA { public void print() { System.out.println("B"); } } } [/CODE] Is there anyway I can write doThing() so that it always calls the ClassA version of print so that when the program runs it prints “A” instead of “B” [/quote] no, you cannot. You will brake LSP (Liskov substitution principle) [quote name='ManaStone' timestamp='1325714846' post='4899723'] [quote name='Telastyn' timestamp='1325713684' post='4899714'] Why would you want to? In general, if you run into this sort of thing where it's hard to do something in the language, it's a hint [i]not to do that.[/i] [/quote]do you know how using Polymorphism caused a problem in one of my programs when a constructor called the wrong function. I've settled the problem, but I would like to be able to avoid in the future. [/quote] post an example of that constructor issue... do you remember how constructors works with subclassing and the role of the "super" keyword?
  • Advertisement