Posts

ios - Concern about memory when choosing between notification vs callback closure for network calls? -

many posts seem advise against notifications when trying synchronize functions, there other posts caution against closure callbacks because of potential inadvertently retain objects , cause memory issues. assume inside custom view controller function, foo , uses bar class data server. class customviewcontroller : uiviewcontroller { function foo() { // other stuff // use bar data server bar.getserverdata() } } option 1: define getserverdata accept callback. define callback closure inside customviewcontroller . option 2: use nsnotifications instead of callback. inside of getserverdata , post nsnotification when server returns data, , ensure customviewcontroller registered notification. option 1 seems desirable reasons people caution against nsnotification (e.g., compiler checks, traceability), doesn't using callback create potential issue customviewcontroller unnecessarily retained , therefore potentially creating memory issues? ...

android - accessing applicationStorageDirectory in Java -

i rewriting application written in adobe air - in native - java. there preferences stored in config.xml in applicationstoragedirectory still access in java code. know how access file in java? in air, applicationstoragedirectory resolves 1 of these paths, depending on os: windows 7 / vista: %userprofile%/appdata/roaming/ application name windows xp: %userprofile%/application data/ application name mac os x: ~/library/preferences/ application name linux (ubuntu): ~/.appdata/ application name android: /data/data/ application name

c - Not handling functions right -

my code supposed make simple menu change armor of character. code is: #include <stdio.h> #include <string.h> struct armor { char chestplate [50]; char helmet [50]; }; void changearmor (){ struct armor character; char [50]; printf("choose chestplate\n"); scanf("%s",&a); strcpy(character.chestplate,a); printf("choose helmet\n"); scanf("%s",&a); strcpy(character.helmet,a); menu(); } void checkarmor () { struct armor character; printf("your equipped chestplate is: %s\n", character.chestplate); printf("your equipped helmet is: %s\n", character.helmet); menu(); } void menu () { int a; printf("what want do?\n"); printf("1.change armor.\n"); printf("2.check current armor.\n"); printf("3.quit\n"); scanf("%d",&a); if(a==1) changearmor; // oops: should changearmor(); ...

nio - Is Filewatcher considered non blocking IO in Java? -

this code snippet filewatcher java 7 nio library. non blocking code? threads waits signal filesystem. for (;;) { // wait key signaled watchkey key; try { key = watcher.take(); } catch (interruptedexception x) { return; } } filewatcher uses epoll linux system call. it's multiplexing mechanism event based. windows there select same thing, far less efficient , in bsd (which osx based on) there kqueue . in simple terms registers event handler in system waiting event occur. time progresses system takes @ queued event handlers , sees if there 1 ready proceed. if there event handler has it's event flag set true handle event. if there no events keep looping until finds event occurred. in meantime code in main continues run, giving "non-blocking" functionality in promises. this isn't new technology, although async has become quite popular rise of nodejs, swift , other non-blocking languages / frameworks same sort o...

linux - multicast loopback in c -

i trying test multicast loopback clients join group , server multicast messgaes client in group constrained in 127.0.0.1 !!!!! refering : http://www.tenouk.com/module41c.html , source : the server : struct in_addr localinterface; struct sockaddr_in groupsock; int sd; char databuf[1024] = "multicast test message lol!"; int datalen = sizeof(databuf); int main (int argc, char *argv[ ]) { /* create datagram socket on send. */ sd = socket(af_inet, sock_dgram, 0); if(sd < 0) { perror("opening datagram socket error"); exit(1); } else printf("opening datagram socket...ok.\n"); /* initialize group sockaddr structure */ /* group address of 225.1.1.1 , port 5555. */ memset((char *) &groupsock, 0, sizeof(groupsock)); groupsock.sin_family = af_inet; groupsock.sin_addr.s_addr = inet_addr("224.0.0.0"); groupsock.sin_port = htons(4321); /* disable loopback not rec...

jms - Cannot create ActiveMQ queue or send a message using java -

i'm new activemq. i'm running activemq server on windows using default settings on local machine. i've tried create simple queue test sending message. public class foo { public static void main(string[] args) { new foo().send(); } public void send(){ try { activemqconnectionfactory connectionfactory = new activemqconnectionfactory("vm://localhost:61616"); connection connection = connectionfactory.createconnection(); connection.start(); session session = connection.createsession(false, session.auto_acknowledge); destination destination = session.createqueue("testqueue"); messageproducer producer = session.createproducer(destination); producer.setdeliverymode(deliverymode.non_persistent); textmessage message = session.createtextmessage("message123"); producer.send(message); session.clos...

Error Number 10170 in Verilog using If/Else and Case Statements -

i trying compile following code whenever errors: '10170 verilog hdl syntax error @ fsm.v(9) near text "case"; expecting operand' '10170 verilog hdl syntax error @ fsm.v(9) near text ")"; epecting "<=" or "="' '10170 verilog hdl syntax error @ fsm.v(11) near text "4"; expecting "end"' module fsm (in0, in1, in2, in3, s, out0, out1, out2, out3); input in0, in1, in2, in3, s; output out0, out1, out2, out3; reg out0, out1, out2, out3; @(in0 or in1 or in2 or in3 or s) begin if(s == 0) begin { case({in3, in2, in1, in0}) 4'b0000: {out3, out2, out1, out0} = 4'b0000; //0->0 4'b0001: {out3, out2, out1, out0} = 4'b0011; //1->3 4'b0010: {out3, out2, out1, out0} = 4'b0110; //2->6 4'b0011: {out3, out2, out1, out0} = 4'b1001; //3->9 4'b0100: {out3, out2, out1, out0} = 4'b0010; /...