What are you working on? V4 (HTML ISN'T PROGRAMMING)
2,003 replies, posted
[QUOTE=Robber;17926544]
[cpp]
// 2.
Button[] buttons=new Button[10];
for(int i=1; i<=buttons.Length; i++)
{
buttons[i]=new Button("Button "+i);
panel.add(buttons[i]);
}[/cpp][/QUOTE]
This was, sort of. It would be better to use a vector or a list for the buttons because you can add as many buttons as you like, while the first method (and using an array) restricts you to a specific number of buttons.
[QUOTE=Mattz333;17926636]This was, sort of. It would be better to use a vector or a list for the buttons because you can add as many buttons as you like, while the first method (and using an array) restricts you to a specific number of buttons.[/QUOTE]
If you have a specific number of buttens, there's no reason to use a vector. And you can avoid the overhead, though it is very small, of a vector.
I've started on my little chat thing again, not much to show but i'll show it anyway.
[img]http://i33.tinypic.com/2l6po0.png[/img]
Gotta get the window movement working :D.
[QUOTE=ddrl46;17926886]I've started on my little chat thing again, not much to show but i'll show it anyway.
[img]http://i33.tinypic.com/2l6po0.png[/img]
Gotta get the window movement working :D.[/QUOTE]
What language / library are you using and how did you get that transparency?
[QUOTE=ZeekyHBomb;17926801]If you have a specific number of buttens, there's no reason to use a vector. And you can avoid the overhead, though it is very small, of a vector.[/QUOTE]
Using a vector you gain things like bounds checking in C++. Which is better than random crashes. That said you could just use a real language or boost::array
[QUOTE=Jallen;17926921]What language / library are you using and how did you get that transparency?[/QUOTE]
I'm using vb.net :sigh:
I've tried to learn C++ but i just can't get it in my head...
Progress
[img]http://i34.tinypic.com/34jc70h.png[/img]
Also got window movement working.
[QUOTE=blankthemuffin;17926923]Using a vector you gain things like bounds checking in C++. Which is better than random crashes. That said you could just use a real language or boost::array[/QUOTE]
Not in release mode (unless you use at()), and most debuggers check for arrays out of bounds. I agree though, boost::array is much better.
Doesn't matter anyways, the code looks like C# to me. Use a ArrayList.
[QUOTE=blankthemuffin;17926923]Using a vector you gain things like bounds checking in C++. Which is better than random crashes. That said you could just use a real language or boost::array[/QUOTE]
You don't always need bounds-checking if you're smart enough.
[QUOTE=ZeekyHBomb;17926989]You don't always need bounds-checking if you're smart enough.[/QUOTE]
But it's always nice to have, even if you are a genius. Humans always make mistakes.
[QUOTE=ZeekyHBomb;17926989]You don't always need bounds-checking if you're smart enough.[/QUOTE]
The bounds-checking is only in debug mode where it is a convenience. In release mode, there is none.
There is no difference between using vector[] and array[] in release mode.
So I further developed my Minesweeper bot and I made it pretty user friendly (which is unusual for me) so I thought why not upload it.
[img]http://filesmelt.com/downloader/MSweeper_bot.png[/img]
[url]http://filesmelt.com/downloader/MSweeper_Bot4.zip[/url]
Read this:
First run the included winmine.exe (Yeah it's German), then MSweeper bot.exe/au3
Turn Aero off in 7 and Vista! It will be [B]really[/B] slow if you don't.
If it goes apeshit, press ESC or PAUSE to close it.
If it fails or wins, press F2 to restart the bot and game.
Change "dim $retryiffail = 0" to 1 if you want it to restart on fail.
If you hate exe's, you can run from the au3 source. You'll need [url=http://www.autoitscript.com/autoit3/downloads.shtml]Autoit3[/url] for that.
It [I]should[/I] work on XP, Vista and Seven.
It'll fail a lot on expert. That's because it has to guess.
It's pretty fast. Completes expert in ~12 seconds, which is a fifth of the world record.
As I said, source is included. You can take a look at the badly written code and change stuff if you want.
If you have suggestions for improvement, tell me! But please don't criticize me for stupid/useless code.
I just wrote a quick program to test this, since I read on some sites that there is an overhead:
[cpp]#include <iostream>
#include <string>
#include <vector>
#define OVERHEAD(type) std::cout << "empty std::vector overhead for " << #type << ": " << static_cast<signed>(sizeof(std::vector<type>)-sizeof(type*)) << std::endl;
int main() {
OVERHEAD(int);
OVERHEAD(char);
OVERHEAD(bool);
OVERHEAD(std::string);
OVERHEAD(std::istream);
return 0;
}[/cpp]
The output of Release- and Debug-mode in VS2010 running on Win 7 64-bit is
[code]empty std::vector overhead for int: 16
empty std::vector overhead for char: 16
empty std::vector overhead for bool: 24
empty std::vector overhead for std::string: 16
empty std::vector overhead for std::istream: 16[/code]
which I find kinda strange. Maybe my Release-mode is somehow wrong configured (although I didn't modify it) or Microsofts implementation is bad.. but you're free to test it on your platform :)
It keeps count the size etc., so it uses a bit more memory.
What I meant was the vector's [] operator compiles to exactly the same code as an arrays [] operator.
Oh. I was talking about memory-overhead :P
Yeah, I think the performance-overhead is none in most modern implementations if you use the same memory-allocating-method :)
Smiley list
[img]http://i38.tinypic.com/2myon12.png[/img]
[QUOTE=Maurice;17927072]So I further developed my Minesweeper bot and I made it pretty user friendly (which is unusual for me) so I thought why not upload it.
[img]http://filesmelt.com/downloader/Minesweeper2.png[/img]
[url]http://filesmelt.com/downloader/MSweeper_Bot4.zip[/url]
Read this:
First run the included winmine.exe (Yeah it's German), then MSweeper bot.exe/au3
Turn Aero off in 7 and Vista! It will be [B]really[/B] slow if you don't.
If it goes apeshit, press ESC or PAUSE to close it.
If it fails or wins, press F2 to restart the bot and game.
Change "dim $retryiffail = 0" to 1 if you want it to restart on fail.
If you hate exe's, you can run from the au3 source. You'll need [url=http://www.autoitscript.com/autoit3/downloads.shtml]Autoit3[/url] for that.
It [I]should[/I] work on XP, Vista and Seven.
It'll fail a lot on expert. That's because it has to guess.
It's pretty fast. Completes expert in ~12 seconds, which is a fifth of the world record.
As I said, source is included. You can take a look at the badly written code and change stuff if you want.[/QUOTE]
Rawr, hottest Minesweeper bot ever.
Anyway, you should make one for Picross
[IMG]http://filesmelt.com/downloader/Wackawackawackawacka.gif[/IMG]
[QUOTE=Alex22;17927696]Rawr, hottest Minesweeper bot ever.
Anyway, you should make one for Picross[/QUOTE]
Funny you mention that, I was just working on a nonogram/picross generator.
Solving is a lot harder tough.
[QUOTE=ZomBuster;17927849]Funny you mention that, I was just working on a nonogram/picross generator.
Solving is a lot harder tough.[/QUOTE]
Which picross game are you using?
(No, I don't wanna beat you to it. I'm too lazy :P)
(Okay maybe.)
I'm not using an existing game, I am making one where you put in any png and it turns it into a picross you can print, and I thought it would be a good idea to make the computer check if it's solvable.
[QUOTE=ZeekyHBomb;17927177]Oh. I was talking about memory-overhead :P
Yeah, I think the performance-overhead is none in most modern implementations if you use the same memory-allocating-method :)[/QUOTE]
There is no overhead. An empty vector takes 28 bytes in memory, a pointer-to-array takes 4, that gives you an amazing 24 bytes overhead, which on a modern machine accounts to 0.0000005% of your computer's memory (assuming 4 GB) if I did that right.
As for the CPU, it compiles to pretty much the same assembly as an array for many operations.
So unless you absolutely need NO feature of vectors (including .size(), any sort of iterators, *anything*), you're better off using them.
EDIT: Fixed some typos and precised array type.
[QUOTE=gparent;17928136]There is no overhead. An empty vector takes 28 bytes in memory, an array takes 4, that gives you an amazingly 24 bytes overhead, which on a modern machine accounts to 0.0000005% of your computer's memory if I did that right.[/QUOTE]
Mmhmm, virtually nothing.
[QUOTE=andersonmat;17928161]Mmhmm, virtually nothing.[/QUOTE]
It's not virtually nothing, it is nothing.
[QUOTE=andersonmat;17920211]
[url]http://www.andersonmatt.com/sc/profile/andersonmat/&json=1[/url]
For jSON encoding :D[/QUOTE]
:love:
[QUOTE=gparent;17928136]There is no overhead. An empty vector takes 28 bytes in memory, a pointer-to-array takes 4, that gives you an amazing 24 bytes overhead, which on a modern machine accounts to 0.0000005% of your computer's memory (assuming 4 GB) if I did that right.[/QUOTE]
It's what I've said. Very small amount of additional memory :)
[QUOTE=thelinx;17928194]:love:[/QUOTE]
Glad I can accommodate you. :dance:
[QUOTE=ZomBuster;17928033]I'm not using an existing game, I am making one where you put in any png and it turns it into a picross you can print, and I thought it would be a good idea to make the computer check if it's solvable.[/QUOTE]
Oh, I totally read that wrong.
You should give me your program when you're done so I can make a bot for it.
[img]http://media.tumblr.com/tumblr_krtmwmhcdd1qa4q72.png[/img]
Text Box!
[QUOTE=r4nk_;17928180]It's not virtually nothing, it is nothing.[/QUOTE]
Everything is something in programming. If it allocates memory, it's something. In this case, it's just not significant.
I've made myself a little app to stream radio.
[img]http://i34.tinypic.com/34xjmer.png[/img]
[QUOTE=ddrl46;17930457]I've made myself a little app to stream radio.
[img]http://i34.tinypic.com/34xjmer.png[/img][/QUOTE]
what did you make that in?
Sorry, you need to Log In to post a reply to this thread.