Блог пользователя nor

Автор nor, 14 месяцев назад, По-английски
  • Проголосовать: нравится
  • +205
  • Проголосовать: не нравится

»
14 месяцев назад, # |
Rev. 2   Проголосовать: нравится -30 Проголосовать: не нравится

Just write this on top of code

#pragma comment(linker, "/STACK:1073741824")

UPD: It does not even work on windows MSVC.

»
14 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Not sure if it'll be helpful to people, but I have the following function in my ~/.bashrc on Mac (should also work on Linux): https://pastebin.com/VV6DCjhx

Usage is cpprun code.cpp and you can optionally append <file.in and/or >file.out for I/O. This will build and run code.cpp, and show the execution time and exit code. It's convenient to me because it's just one line.

You may have to tweak the line with the g++ build flags. In particular, the flags -Wl,-stack_size -Wl,20000000 is what I've found to work most consistently on Mac for increasing stack limit.

»
14 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I used the template but got the following:

Errors while compiling:
C:\Users\roysh\AppData\Local\Temp\ccBV77oY.s: Assembler messages:
C:\Users\roysh\AppData\Local\Temp\ccBV77oY.s:579: Error: bad register name `%rsp'
C:\Users\roysh\AppData\Local\Temp\ccBV77oY.s:580: Error: bad register name `%rsp'
C:\Users\roysh\AppData\Local\Temp\ccBV77oY.s:589: Error: bad register name `%rsp'

What could be the possible reason for this?

  • »
    »
    14 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

    Do you have a 32 bit machine or 64 bit machine? From the small amount of assembly I remember, I have a feeling this might be an issue. Maybe using esp instead of rsp can help.

    • »
      »
      »
      14 месяцев назад, # ^ |
      Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

      I have a 64 bit machine but maybe 32bit MinGW is installed, never bothered before...

      Could you please share or let me know any tutorial for 64bit cpp installation? Would be really helpful...

      UPD: Worked after using 'esp' in place of 'rsp'... , Thanks

»
14 месяцев назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Why and How does this works?

  • »
    »
    14 месяцев назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    It allocates a stack and manually changes the stack pointer before and after the function call.

»
14 месяцев назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

ok now I know why my solution crashed in my computer during hacker cup 2021 but later it worked on other people's computers , thanks

»
14 месяцев назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

I just use this while compiling c++ file in windows: g++ "-Wl,--stack,1078749825" file_name.cpp -o output

»
14 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks a ton!

»
14 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

not working in codeblocks

I really need it, a program won't run because I have an array that's way too big. Any idea what I could do, and do it fast?

  • »
    »
    14 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Try declaring array globally. It might work

  • »
    »
    14 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    What is the error message? It should not be an issue with an IDE, but with the OS/architecture of your machine/target of compiler. If it is Windows and your compiler is 32 bit instead of 64 bit, you can try using esp instead of rsp. If you're using a machine with an ARM chip, this won't work.

    • »
      »
      »
      13 месяцев назад, # ^ |
      Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

      it wasn't an error message. Here is more context:

      I had a class containing a vector of a struct with 2 ints and a double of size 1e6. Although it did compile, it immediately crashed when I tried to run it. When I tried to catch where it crashed with F8 (a shortcut in CodeBlocks) it didn't catch anything and just failed, leaving me to wonder wtf is causing it. When I took everything out of the class, it all ran fine.

      I don't know what esp, rsp or an ARM chip are. I'll try to read up on it lol

      Here is what I got when I tried to run the code you provided here, sorry but I have no idea what to make of these errors lmao https://ibb.co/CMw2twK

      • »
        »
        »
        »
        13 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        The struct should not have been an issue. The screenshot looks like a compilation error, seems like the error is in the debug build instead.

        One thing you can try is find and replace "rsp" in the code above by "esp" — if your execution crashed due to architecture issues (32 bit vs 64 bit), then it should most likely be fixed by this change.

»
3 месяца назад, # |
Rev. 3   Проголосовать: нравится -8 Проголосовать: не нравится

hey nor I did what u said but it is not woriking , can u please help . The input is working but the output file is not showing after test case 46

*** ( ok , now it is woriking for run_with_stack_size( solve , 512 * 512 * 512 ) nut not for run_with_stack_size( solve , 1024 * 1024 * 1024) . Will it be enough for contest in hacker cup ?? ) ***

This is code

anyone ?

  • »
    »
    3 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    The function allocates a very large buffer. If you do that for every test case, you will most likely get TLE.

    The way to use the template is to write your main function in a separate function (not your solve function), and call that function via the stack size function only once in main and do nothing else.

»
7 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hey, I am using macOS and while setting up with the reference of blog I have used the function mentioned and it looks like:

Code

And I am facing error:

Error

Any help would be appreciated!

»
7 недель назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Above link is not working --> Check this Click Here