• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:56
CET 14:56
KST 22:56
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1426 users

The Big Programming Thread - Page 643

Forum Index > General Forum
Post a Reply
Prev 1 641 642 643 644 645 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 20 2015 11:23 GMT
#12841
--- Nuked ---
Ropid
Profile Joined March 2009
Germany3557 Posts
June 20 2015 11:31 GMT
#12842
You could put those x and y together with the pointer to the buffer, so that might be nice.

I'm trying to think about what this will do to make things better, but I'm failing, can't get to a clear opinion.
"My goal is to replace my soul with coffee and become immortal."
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
June 20 2015 11:46 GMT
#12843
On June 20 2015 20:23 Nesserev wrote:
Show nested quote +
On June 20 2015 20:07 Manit0u wrote:
And what if I put range and other stuff into a struct? Would that be a good idea?

Somehow I completely forgot about structs...

It's probably a good idea to bundle the array and its size in a simple struct, because when the array is returned, you only get the pointer to the array back, but you don't know what the size of said array is.

But I get the impression (sorry if I'm wrong, the internet :S) that you're thinking of addings some sort of destructor to that struct... but in C, structs can only be used to organize data, and can't have any 'class methods'. So, structs won't solve any problems on that front.


I seem to vaguely recall that in the past I used to create some functions to release the memory...

Yeah. Found it. Not sure if it's the working version though, but I can definitely use something like that:


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration(void);
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);
//void CheckExit(struct DiceConfiguration *config);
int CheckContinue(void);
void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result);

int main(void)
{
int ThrowAgain;
struct DiceConfiguration *config;
struct DiceThrowsResult *result;

do
{
srand((unsigned int) time(0)); // random seed

config = GetConfiguration();

//CheckExit(config);

result = ThrowDices(config);

PrintDiceThrowsResult(result);

ThrowAgain = CheckContinue();
}while(ThrowAgain = 1);

ReleaseMemory(config, result);

return 0;
}

struct DiceConfiguration* GetConfiguration(void)
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

printf("Entering \"0\" (zero) will exit the program.\n");
printf("Enter the number of dice: ");
scanf("%d", &config->DiceNumber);
printf("Enter dice type (sides) : ");
scanf("%d", &config->DiceType);

return config;
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i]);
}

printf("Sum: %d\n", result->Sum);
}

/*
void CheckExit(struct DiceConfiguration *config)
{

if (config->DiceNumber = 0 || config->DiceType = 0)
{
printf("Closing generator...\n");
break;
}
}
*/

int CheckContinue(void)
{
char ContinueDecision;
int AdjustLoop;

printf("Would you like to throw the dice again? (y/n): ");
ContinueDecision = getchar();
while(getchar() != '\n');

if(ContinueDecision = 'y')
{
AdjustLoop = 1;
}

if(ContinueDecision = 'n')
{
AdjustLoop = 0;
}

return AdjustLoop;
}

void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result)
{
if (config != NULL)
{
free(config);
config = NULL;
}

if (result != NULL)
{
free(result);
result = NULL;
}
}
Time is precious. Waste it wisely.
Itsmedudeman
Profile Blog Joined March 2011
United States19229 Posts
June 22 2015 12:29 GMT
#12844
Cool stuff. Was fun going through some of the code in the past few pages. Our school used a lot of C but I'm still not completely sound with how memory allocation is done. One question though, what does return "x > ?" do? Is that a typo and it should instead be "x > y ?" or is there some default behavior it does with the > sign?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 22 2015 13:30 GMT
#12845
--- Nuked ---
Itsmedudeman
Profile Blog Joined March 2011
United States19229 Posts
June 22 2015 13:38 GMT
#12846
This line in particular:


return x > ? fill_range(x, size, range, 1) : fill_range(x, size, range, 0);


The code itself might not have been compiled and may have just been an idea he was throwing around looking back on his post.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 22 2015 13:40 GMT
#12847
--- Nuked ---
Acrofales
Profile Joined August 2010
Spain18110 Posts
June 22 2015 14:45 GMT
#12848
On June 20 2015 07:35 Manit0u wrote:
Show nested quote +
On June 20 2015 07:21 RoyGBiv_13 wrote:
On June 20 2015 06:24 Manit0u wrote:
Guys, how do you structure C projects? I've never written anything complex in C before but I plan on changing that and was wondering if there is any kind of "standard" folder structure or anything like that.

I was thinking about something along the lines of this:


/bin
-- executables go here
/config
-- makefiles, misc config files
/data
-- sqlite databases, images etc.
/scripts
-- Lua and other stuff
/src
/ext
-- external libraries (other people's stuff and such)
/lib
-- actual c code goes here
/sys
-- headers go here


Would that be any good? Or should I perhaps keep config, data and scripts inside the src folder?


I've got a ton of experience with QNX, though it's been a few years I actually did any projects with it since now I work for a competitor.

That directory structure looks fine, I might put your actual C code in /src, and put external libraries in /lib and headers in /src/include or just /include.
Your Makefile and README should go in the root directory, not /config, but that doesn't mean you shouldn't have a folder for storing random configuration files in it as well, which may include other Makefiles being imported with various compiler options being defined.

Depending on what your project's end output file will be, I prefer to place my project folder within the same folder as the examples for the OS. The benefit is that a lot of your code is going to be copied over from those examples, and that you can put the entire OS in version control along with your project (which you should do, in case you accidentally change something you shouldn't have).

+ Show Spoiler +
If you want to open source your project, don't do this if you had to have a license to decrypt the OS libraries in the first place to install them. If the OS you are using is already open source, consider branching it instead of making a new repository


You'll also need a obj/ folder for storing intermediate object files.


With the structure I wasn't asking about QNX specifically. I'm just toying around with ANSI C in my leisure time.

I was asking about QNX because a friend of mine asked me for help and I simply can't refuse stuff that involves learning some new code. The task at hand was relatively simple but I've found QNX's online documentation to be pretty lacking (as in, requiring you to have really good knowledge of the system to understand it, at which point you probably don't need it). I also hat it when they always seem to do for( ; ; ) instead of while(true) or something. But I digress...

The problem he had to solve was the password/pin thingie. Where you give the user a message, wait 5 seconds for input and reset ad infinitum. The task specifically asked to use the alarm() function. While making a simple loop and doing alarm(5) inside of it is easy, actually handling the alarm is not. From what I read in the docs, when the time for the alarm elapses, it sends the SIGALRM which kills the current process, thus exiting the loop and all. I've read that you should handle this signal with sigaction() or somesuch but I couldn't really find a way to make sigaction() resume/restart the loop.

Could you shed some light on the matter?

Show nested quote +
On June 20 2015 07:35 RoyGBiv_13 wrote:
Manit0u's fixed implementation allows the user of the function to allocate the memory where they want, instead of forcing it onto the heap.


Is it a bad thing?

Edit:

Also, the code purist in my heart tells me to refactor the code, remove fill_range_reverse and simply pass another argument to the fill range function (a boolean) that controls incrementation/decrementation inside of the loop to remove code duplication.

+ Show Spoiler [like so] +


#include <stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y));
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y));

// prototypes
int factorial(int n);
int sum(int n);
int check_increment(int x, int reverse)
int* fill_range(int x, int size, int* range, int reverse);
int* irange(int x, int y);

int main()
{
int fac = factorial(5);
int* range1 = irange(1, 10);
int* range2 = irange(10, 1);
int i = 0;

printf("Factorial of 5 is: %d\n", fac);

for (i = 0; i < 10; ++i)
{
printf("Normal range %d: %d\n", i, range1[i];
}

for (i = 0; i < 10; ++i)
{
printf("Reverse range %d: %d\n", i, range2[i];
}

return 0;
}

int factorial(int n)
{
if (n < 2)
return 1;

return (n * factorial(n - 1));
}

int sum(int n)
{
return ((n * (n + 1)) / 2);
}

int check_increment(int x, int reverse)
{
return reverse ? x -= 1 : x += 1;
}

int* fill_range(int x, int size, int* range, int reverse)
{
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x = check_increment(x, reverse);
}

return range;
}


int* irange(int x, int y)
{
int size = MAX(x, y) - MIN(x, y) + 1;
int range[size];

return x > ? fill_range(x, size, range, 1) : fill_range(x, size, range, 0);
}



Question: why use a boolean flag, rather than directly give the incrementation step. Sure, this could lead to code like passing a step size of 2, which may result in unexpected behaviour down the line (but I don't really see why) and it would make your check_increment (which I feel is ugly) method redundant like so:

int* fill_range(int x, int size, int* range, int step)
{
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x += step;
}

return range;
}

int* irange(int x, int y)
{
int size = MAX(x, y) - MIN(x, y) + 1;
int range[size];

return x > y? fill_range(x, size, range, 1) : fill_range(x, size, range, -1);
}
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
June 22 2015 16:39 GMT
#12849
an easier to read return would be
return fill_range(x, size, range, (x > y ? 1 : -1));

just sayin
Liquipediaasante sana squash banana
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 22 2015 20:18 GMT
#12850
--- Nuked ---
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
June 22 2015 20:50 GMT
#12851
On June 23 2015 05:18 Nesserev wrote:
Personally, I kinda dislike the conditionat operator, and prefer a simple 'if ... else ...' structure in most cases. One of the problems is that code using the conditional operator looks very cluttered, very fast. My personal rules for using it are:
- don't embed it in other code (separate statement on its own)
- the statement has to be very short and simple, so that your brain can immediately interpret what's going on.

Absolutely agree with that. If nothing else, separating the statement at least allows you to give it a reasonable name.
If you have a good reason to disagree with the above, please tell me. Thank you.
Khalum
Profile Joined September 2010
Austria831 Posts
Last Edited: 2015-06-22 21:16:35
June 22 2015 21:13 GMT
#12852
I have altered the way I write a lot over the years since there are quite a few things to consider and I'm still not convinced that I've found the sweetspot. I want my code to be readable but don't want to write novels - and sometimes that's tricky.

For example I always use brackets for if/else statements when it's part of the "intended" flow but I keep early exit checks as short as possible, like
 if (..) throw std::exception(..);
all in one line.

I like to do it that way because I feel like it creates a better "balance" when you look at the code. First get all the necessary checks out of the way quickly and then do the actual work. When I look at code that is very excessive when it comes to just doing simple things I feel like it distracts from the actually relevant stuff. It's kinda hard to explain for me right now, it's like a gut feeling - it's inaesthetic to me... the rhytm is somehow off... you get my point.

On the other hand it's of course not just hard to read at times but can also be a nightmare when debugging things when you put too much stuff into one statement. So the "main functionality" of any function would be written in a more verbose way.

What I found myself doing a lot is stuff like
typedef std::vector<SomeType> SomeTypeVector;
typedef SomeTypeVector::iterator SomeTypeVectorIt;
which enables me to write more explicit code afterwards without unnecessary clutter. It's just important to pick representative names - but that's true for everyting you give a name.

And then there's templates. Incredibly useful yet incredibly shitty to read at a certain complexity level..

[edit]
I actually wanted to respond to the return statement criticism. The if/else would - in my opinion - not be an improvement. What I'd do is:
int step = x>y ? 1 : -1;
return fill_range( x, size, range, step );
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
June 22 2015 21:22 GMT
#12853
Thanks for the good suggestions. Obviously the code I wrote was something I did in a hurry to simply spill my brains. It shall be refactored over time.
Time is precious. Waste it wisely.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2015-06-23 04:29:48
June 23 2015 00:53 GMT
#12854
===The RoyGBiv quick guide to memory management in C===

There are many different places where data exist, and every time you use data, it has to be stored somewhere in memory. This guide will provide a set of rules for how to ensure your C program never leaks memory nor loses valid data.

======
To begin, lets define how data is passed in the C language:

Passing by Reference: All data exist at some address where it can be accessed, when calling a function, passing the address where data is stored rather than the data itself is known as Passing by Reference.

Passing by Value: When calling a function, passing the data itself will make a copy of that data, and put it on the Stack.

For example,

int debug_printf(char * buffer, int len);
int main()
{
char* foo = "Hello World"; // "Hello World" is put onto the Stack here
debug_printf(foo, strlen(foo));
}

int debug_printf(char * buffer, int len)
{
//"Hello World" is still within the stack frame for
buffer[len] = "\n"
buffer[len+1] = 0;
printf("%s", buffer);
return 1;
}

========

Let's also define all the regular places where data can be stored in memory in a C program:


Stack: Every process of every program contains a section of memory in RAM called the stack. At the beginning of every function call, a new "Stack Frame" is pushed (added) onto the top of the stack. This Stack Frame contains the address the program is supposed to branch to upon returning from that function call, along with any variables declared within that function. A Stack Frame is popped (removed) when returning from a function, and all the variables that had data stored within that Stack Frame are no longer valid. Since the stack is used in every function call, running out of space in the stack is very bad and you will segfault (or worse).

Heap: programs have a section of memory in RAM where you can allocate and free memory programatically. Unlike the stack, where data has a lifespan dependent on the function it is declared in, the heap will keep the data until explicitly told it no longer needs to. This region of memory is typically very large, and the Operating System will usually continue to expand this if your program needs even more space.

Linker Sections: when building your program, global variables and structures will be placed into memory when your program loads. Data located in global variables and structures will be placed in one of several linker sections depending on whether it is initialized or declared as constant. Uninitialized data will be placed in the ".bss" section to be cleared quickly when loading the program. Initialized, non-constant data will be placed in the ".data" section, and constant data will be placed in the ".rodata" section. The ".rodata" section is special as it may not be present in RAM, but rather read-only memory.
========

One of the very important parts of writing Fast C code is to reduce the number of times where you have to copy the same data if it's being accessed by the same program. In addition, each time you copy memory, you have one more piece of data to ensure is freed at the right time. Thus, it's important to place your data in the right spot where it will always be valid when you need it and pass the data around via reference rather than value to avoid copying larger buffers. This can be done by statically allocating when possible, and putting small variables on the stack.

If a char, short, int, long, float, double, string, buffer or struct does not change its value during a program, make it a global const.

If a char, short, int, long, float, double, statically sized string, statically sized buffer or struct is accessed regularly throughout the program during various functions declare it as a global outside any function (or static to reduce it's scope to just that file or function).

A char, short, int, long, float, or double should be declared on the stack and can be passed by value or reference. If you don't know which function to declare it in, start at main() and work your way down to the first level which uses the value, then declare it there.

A dynamically sized buffer or string can be declared on the stack, if it is small (my rule of thumb is under 100 bytes or 1 line in a file), or placed on the heap if it is large. It should always be passed by reference.

As for data structures (like lists, sets, variable length arrays), C++ containers tend to store copies of data added to them on the heap. When destroying the container, it has recorded all the memory it used, and frees it. I like that model of dynamic memory management.


======
FAQ:

Q: You say "buffer", do you mean array?
A: Both words refer to the same thing, a contiguous block of memory, but are generally used to reflect how the underlying data are used. In this case, since I'm referring to size it takes up within RAM, I use "buffer".

Q: What If i'm writing a new function to modify existing data?
A: There are two ways to modify data, either modify it in place, or make a copy, modify that copy, and return it. When possible, you should modify data in place, and allow the calling function decide whether it wants to copy the data or not.

Q: I have a function that needs to return a large buffer, should I put it on the heap and return it?
A: Instead, pass a reference to the function that already has space allocated. The calling function is then able to decide where to put the buffer. If this convention is used throughout the program, it is very easy to ensure you never leak memory.

Q: Is there anything wrong with declaring every variable in the program as a global?
A: In practice, no. This just means your program is simple enough to allocate all memory it needs during its build, and does not need to programatically allocate anything. Teachers might get upset if you get in this practice, though, since you aren't learning anything about memory management. It could also bloat the size of your program if you put huge amounts of initialized data in your .data or .rodata section.

Q: What about smart pointers, like auto_ptr in C++?
A: C has a few implementations of smart pointers itself, and you are welcome to use them or create your own. If you are having trouble ensuring your heap memory is properly free'd, try thinking of the heap as an extension of the stack. Put all of your malloc() calls at the start of a function and free() at the end of the same function. Now you know the scope of that memory.

Q: What happens if you mistakenly use a reference to no longer valid data?
A: If you reference old data in the heap, this is called a "use after free" bug, and a great many tools exist to find these. Potentially, other calls to malloc could reallocate that space and you would be using whatever data was there. Similarly, referencing stack memory that has been popped will likely reference another stack frame's data, which may look valid but be incorrect. These can be some of the hardest bugs to find or debug.

Q: What is a "Stack Overflow" or "Buffer Overflow"
A: When a buffer is allocated on the stack, it reserves a fixed size determined by how large the buffer is. If you don't check your bounds before writing to or reading from that buffer, it's possible to mistakenly write past the end of the buffer. If you write far enough, it's possible to cross neighboring data in the same data structure, such as the next stack frame. This ia called a "Buffer Overflow". Since a stack frame includes an executable address to return to, a malicious Stack Overflow could overwrite that value, and cause the program to execute code that they located anywhere on the system.

A "Stack Overflow" happens when the stack's size becomes too large for the space allocated for it. This can happen often during runaway recursion or if you allocate an enormous buffer to the stack. If you are running as a virtual process, many operating systems intentionally leave a bit of memory past the stack as unmapped. This causes programs that go past the end of the stack to segfault or throw a page fault instead of overwriting another processes.
Any sufficiently advanced technology is indistinguishable from magic
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 23 2015 15:32 GMT
#12855
--- Nuked ---
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
June 23 2015 16:10 GMT
#12856
On June 23 2015 09:53 RoyGBiv_13 wrote:
Passing by Reference: All data exist at some address where it can be accessed, when calling a function, passing the address where data is stored rather than the data itself is known as Passing by Reference.

"Passing by Reference" in quotes. It actually is Pass by Value, where the value is the address. As far as I'm aware there is no actual Pass by Reference in C. It's similar in practice, but technically not the same.
If you have a good reason to disagree with the above, please tell me. Thank you.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
June 23 2015 19:18 GMT
#12857
On June 23 2015 09:53 RoyGBiv_13 wrote:
A dynamically sized buffer or string can be declared on the stack, if it is small (my rule of thumb is under 100 bytes or 1 line in a file), or placed on the heap if it is large. It should always be passed by reference.

You mean if the buffer is big you want to pass it by reference right?

Nice guide btw, I enjoyed it alot.
The harder it becomes, the more you should focus on the basics.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
June 23 2015 21:25 GMT
#12858
Java question:

I have multiple lists of possibly > 10K integers, how do I efficiently perform computations on multiple lists at the same time? The lists get paged out a lot so it's really slow on large sets.
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 23 2015 21:50 GMT
#12859
--- Nuked ---
Acrofales
Profile Joined August 2010
Spain18110 Posts
June 23 2015 21:57 GMT
#12860
I agree with Nesserev. Java sounds less than ideal for that. Wrapping each int in an Integer object and wrapping your array in a List is going to create a lot of overhead, regardless of how efficient you are at coding that.

Other than that, we need more details. There is no magic solution (other than using C for that shit).
Prev 1 641 642 643 644 645 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6776
Horang2 4135
GuemChi 1585
Jaedong 890
actioN 290
Mini 250
BeSt 249
Soma 228
Killer 218
EffOrt 205
[ Show more ]
Rush 172
Mind 105
Hyun 95
Bonyth 72
ToSsGirL 67
Backho 60
PianO 34
JYJ32
sas.Sziky 32
Aegong 28
zelot 23
Terrorterran 14
soO 11
sorry 10
HiyA 7
Sacsri 7
Dota 2
Gorgc5272
singsing2292
qojqva1976
Dendi596
XcaliburYe219
BananaSlamJamma107
Heroes of the Storm
Khaldor214
Other Games
B2W.Neo1235
Sick275
Lowko237
Fuzer 197
Hui .121
XaKoH 87
nookyyy 56
MindelVK20
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL231
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 73
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2101
League of Legends
• Stunt689
• HappyZerGling108
Upcoming Events
IPSL
4h 5m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 5m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 5m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 5m
Sparkling Tuna Cup
20h 5m
WardiTV Korean Royale
22h 5m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.