Search Results

Search found 467 results on 19 pages for 'weak'.

Page 1/19 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Weak hashmap with weak references to the values?

    - by Razor Storm
    I am building an android app where each entity has a bitmap that represents its sprite. However, each entity can be be duplicated (there might be 3 copies of entity asdf for example). One approach is to load all the sprites upfront, and then put the correct sprite in the constructors of the entities. However, I want to decode the bitmaps lazily, so that the constructors of the entities will decode the bitmaps. The only problem with this is that duplicated entities will load the same bitmap twice, using 2x the memory (Or n times if the entity is created n times). To fix this, I built a SingularBitmapFactory that will store a decoded Bitmap into a hash, and if the same bitmap is asked for again, will simply return the previously hashed one instead of building a new one. Problem with this, though, is that the factory holds a copy of all bitmaps, and so won't ever get garbage collected. What's the best way to switch the hashmap to one with weakly referenced values? In otherwords, I want a structure where the values won't be GC'd if any other object holds a reference to it, but as long as no other objects refers it, then it can be GC'd.

    Read the article

  • weak or strong for IBOutlet and other

    - by Piero
    I have switched my project to ARC, and I don't understand if I have to use strong or weak for IBOutlets. Xcode do this: in interface builder, if a create a UILabel for example and I connect it with assistant editor to my ViewController, it create this: @property (nonatomic, strong) UILabel *aLabel; It uses the strong, instead I read a tutorial on RayWenderlich website that say this: But for these two particular properties I have other plans. Instead of strong, we will declare them as weak. @property (nonatomic, weak) IBOutlet UITableView *tableView; @property (nonatomic, weak) IBOutlet UISearchBar *searchBar; Weak is the recommended relationship for all outlet properties. These view objects are already part of the view controller’s view hierarchy and don’t need to be retained elsewhere. The big advantage of declaring your outlets weak is that it saves you time writing the viewDidUnload method. Currently our viewDidUnload looks like this: - (void)viewDidUnload { [super viewDidUnload]; self.tableView = nil; self.searchBar = nil; soundEffect = nil; } You can now simplify it to the following: - (void)viewDidUnload { [super viewDidUnload]; soundEffect = nil; } So use weak, instead of the strong, and remove the set to nil in the videDidUnload, instead Xcode use the strong, and use the self... = nil in the viewDidUnload. My question is: when do I have to use strong, and when weak? I want also use for deployment target iOS 4, so when do I have to use the unsafe_unretain? Anyone can help to explain me well with a small tutorial, when use strong, weak and unsafe_unretain with ARC?

    Read the article

  • Weak-linking with static libraries

    - by Jaakko L.
    I have declared an external function with a GCC weak attribute in a .c file: extern int weakFunction( ) __attribute__ ((weak)); Compiled object file has weakFunction defined as a weak symbol. Output of nm: 1791: w weakFunction I am calling the weak defined function as follows: if (weakFunction != NULL) { weakFunction(); } When I link the program by defining the object files as parameters to GCC (gcc main.o weakf.o -o main.exe) weak symbols work fine. If I leave the weakf.o out of linking, the function address is NULL in main.c and the function won't be called. Problem is, when weakf.o is inside a static library, for some reason the linker doesn't find the function and the function address always ends up being NULL. Static library is created with ar: ar rcs weaklibrary weakf.o Anyone had similar problems?

    Read the article

  • When to use weak references in Python?

    - by bodacydo
    Can anyone explain usage of weak references? The documentation doesn't explain it precisely, it just says that the GC can destroy the object linked to via a weak reference at any time. Then what's the point of having an object that can disappear at any time? What if I need to use it right after it disappeared? Can you please explain them with some good examples? Thanks, Boda Cydo.

    Read the article

  • Alternatives to weak linking in iPhone SDK?

    - by Moshe
    I'm looking to make my app compatible with older versions of iPhone OS. I did see weak linking mentioned as an option. Can I use OS version detection code to avoid code blocks that the OS can't handle? (Say iAD?) if(OS >= 4.0){ //set up iADs using "NDA code"... } If yes, what goes in place of if(OS >= 4.0)?

    Read the article

  • Does weak typing offer any advantages?

    - by sub
    Don't confuse this with static vs. dynamic typing! You all know JavaScripts/PHPs infamous type systems: PHP example: echo "123abc"+2; // 125 - the reason for this is explained // in the PHP docs but still: This hurts echo "4"+1; // 5 - Oh please echo "ABC"*5; // 0 - WTF // That's too much, seriously now. // This here might be actually a use for weak typing, but no - // it has to output garbage. JavaScript example: // A good old JavaScript, maybe you'll do better? alert("4"+1); // 51 - Oh come on. alert("abc"*3); // NaN - What the... // Have your creators ever heard of the word "consistence"? Python example: # Python's type system is actually a mix # It spits errors on senseless things like the first example below AND # allows intelligent actions like the second example. >>> print("abc"+1) Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print("abc"+1) TypeError: Can't convert 'int' object to str implicitly >>> print("abc"*5) abcabcabcabcabc Ruby example: puts 4+"1" // Type error - as supposed puts "abc"*4 // abcabcabcabc - makes sense After these examples it should be clear that PHP/JavaScript probably have the most inconsistent type systems out there. This is a fact and really not subjective. Now when having a closer look at the type systems of Ruby and Python it seems like they are having a much more intelligent and consistent type system. I think these examples weren't really necessary as we all know that PHP/JavaScript have a weak and Python/Ruby have a strong type system. I just wanted to mention why I'm asking this. Now I have two questions: When looking at those examples, what are the advantages of PHPs and JavaScripts type systems? I can only find downsides: They are inconsistent and I think we know that this is not good Types conversions are hardly controllable Bugs are more likely to happen and much harder to spot Do you prefer one of the both systems? Why? Personally I have worked with PHP, JavaScript and Python so far and must say that Pythons type system has really only advantages over PHPs and JavaScripts. Does anybody here not think so? Why then?

    Read the article

  • OSX Weak Linking - check if a class exists and use that class

    - by psychotik
    I'm trying to create a universal iPhone app, but it uses a class defined only in a newer version of the SDK. The framework exists on older systems, but a class defined in the framework doesn't. I know I want to use some kind of weak linking, but any documentation I can find talks about runtime checks for function existence - how do I check that a class exists?

    Read the article

  • Simple Data Caching using Weak References in WCF

    - by Tawani
    Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string state) { var db = new LookUpRepository(); return db.GetCounties(state); } } class County { public string StateCode{get;set;} public string CountyName{get;set;} public int CountyCode{get;set;} } What will be the most efficient (or best) way to cache a state's counties using weak references (or any other approach) so that we don't hit the database every time we need to look up data. Note that we will not have access to the HttpRuntime (and HttpContext).

    Read the article

  • Static/Dynamic vs Strong/Weak

    - by Dan Revell
    I see these terms banded around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I'm aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different different meanings or even use the terms interchangeably. I can't find somewhere that talks about both and actually spells out the difference. What would be nice is if someone could please spell this out clearly here for me and the rest of the world.

    Read the article

  • AS3: Weak Listener References Not Appropriate During Initialization?

    - by TheDarkIn1978
    as i currently understand, if an event listener is added to an object with useWeakReference set to true, then it is eligible for garbage collection and will be removed if and when the garbage collection does a sweep. public function myCustomSpriteClass() //constructor { this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener, false, 0, true); this.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener, false, 0, true); } in this case, is it not appropriate to initialize an object with weak references event listeners, incase the garbage collector does activate a sweep removing the objects event listeners since they were added during initialization of the object? in this case, would it only be appropriate to create a type of deallocate() method which removes the event listeners before the object is nullified?

    Read the article

  • How to avoid XCode framework weak-linking problems?

    - by Frank R.
    Hi, I'm building an application that takes advantage of Mac OS X 10.6-only technologies, but without giving up backwards compatibility to 10.5 Leopard. The way I do this is by setting the 10.6 SDK as the base SDK, weak-linking all frameworks and setting the deployment target to 10.5 as described in: http://developer.apple.com/mac/library/DOCUMENTATION/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html This works fine; before making a call that is Snow Leopard-only I need to check that the selector or indeed the class actually exist. Or I can just check the OS version before making the call. The problem is that this is incredibly fragile. If I make a single call that is 10.6 only I blow Leopard-compatibility. So using even the normal code code completion feature can be dangerous. My question: is there any way of checking which calls are not defined on 10.5 before doing a release build? Some kind of static analysis, or even just a trick (a target set the other SDK?) would do. I obviously should test on a Leopard machine before releasing anything, but even so I can't possibly go through all paths of the program before every release. Any advice would be appreciated. Best regards, Frank

    Read the article

  • Weak linking on iPhone refuses to work

    - by Jonathan Grynspan
    I've got an iPhone app that's mainly targetting 3.0, but which takes advantage of newer APIs when they're available. Code goes something like this: if (UIApplicationDidEnterBackgroundNotification != NULL) [nc addObserver: self selector: @selector(irrelelvantCallbackName:) name: UIApplicationDidEnterBackgroundNotification object: nil]; Now, according to everything Apple's ever said, if the relevant APIs are weakly linked, that will work fine because the dynamic linker will evaluate UIApplicationDidEnterBackgroundNotification to NULL. Except that it doesn't. The application compiles, but as soon as it hits "if (UIApplicationDidEnterBackgroundNotification != NULL)" it crashes with EXC_BAD_ACCESS. Is this simply a matter of a compiler flag I need to set? Or am I going about this the wrong way?

    Read the article

  • Python - how to check if weak reference is still available

    - by Alex
    Hi all, I am passing some weakrefs from Python into C++ class, but C++ destructors are actively trying to access the ref when the real object is already dead, obviously it crashes... Is there any Python C/API approach to find out if Python reference is still alive or any other known workaround for this ? Thanks

    Read the article

  • .NET Weak Event Handlers – Part II

    - by João Angelo
    On the first part of this article I showed two possible ways to create weak event handlers. One using reflection and the other using a delegate. For this performance analysis we will further differentiate between creating a delegate by providing the type of the listener at compile time (Explicit Delegate) vs creating the delegate with the type of the listener being only obtained at runtime (Implicit Delegate). As expected, the performance between reflection/delegate differ significantly. With the reflection based approach, creating a weak event handler is just storing a MethodInfo reference while with the delegate based approach there is the need to create the delegate which will be invoked later. So, at creating the weak event handler reflection clearly wins, but what about when the handler is invoked. No surprises there, performing a call through reflection every time a handler is invoked is costly. In conclusion, if you want good performance when creating handlers that only sporadically get triggered use reflection, otherwise use the delegate based approach. The explicit delegate approach always wins against the implicit delegate, but I find the syntax for the latter much more intuitive. // Implicit delegate - The listener type is inferred at runtime from the handler parameter public static EventHandler WrapInDelegateCall(EventHandler handler); public static EventHandler<TArgs> WrapInDelegateCall<TArgs>(EventHandler<TArgs> handler) where TArgs : EventArgs; // Explicite delegate - TListener is the type that defines the handler public static EventHandler WrapInDelegateCall<TListener>(EventHandler handler); public static EventHandler<TArgs> WrapInDelegateCall<TArgs, TListener>(EventHandler<TArgs> handler) where TArgs : EventArgs;

    Read the article

  • B.S.in Computer Science, weak eyes => career change

    - by Prometheus
    So I am going to earn B.S. in Computer Science soon. I like computers. I like programming. The problem is that my eyes are very weak. Depending on their condition, I can only put in about 6 hours in front of computer a day. If I push myself, I have trouble even keeping my eyes open because of soreness/pain, consequently headaches. My eyes do not have medical conditions. I was just born with weak eyes. I tried many different approaches to work around this problem - better monitor, breaks every 10 minutes, supplements... I even memorized a lot of shortcuts to reduce my time on computers! But I am finally giving up. I do not think I can be a programmer for the rest of my life. I was the top of my class in high school because all works were paper-based, I did average in college due to the nature of my eyes and the difficulty of the material. So what do you recommend I do? Or, Is there a career that is similar to programming but requires interacting with computers less?

    Read the article

  • Cost to GC of using weak references in C#?

    - by Scott Bilas
    In another question, Stephen C says: A second concern is that there are runtime overheads with using weak references. The obvious costs are those of creating weak references and calling get on them. A less obvious cost is that significant extra work needs to be done each time the GC runs. So what exactly is the cost to the GC of a weak ref? What extra work does it need to do, and how big of a deal is it? I can make some educated guesses, but am interested in the actual mechanics.

    Read the article

  • Great Debugging skills weak problem solving

    - by Mahmoud
    For the 5 years I worked for various companies, I worked in large software like computer vision kits, embedded, games. I found myself very good at debuggins skills, I've even found and fixed bugs in frameworks and I solved them. The problem is that I'm very weak at problem solving. I got interview with Qualcomm, and they said you're fine at software, but you have a limited problem solving, I also had the same results with Google. I'm very bad at solving puzzles and brain teasers. During the interviews I solve all of the software related problems on the blackboard, but when I went to the GM and face math problems and probabilities, I struggle. How can I improve my problem solving skills? Edit Some of the problems: A cake that is cut from anywhere and needs just one cut to halved in equal. I told him cut it horizontally, he said No, consider it as a 2D Problem!. Consider a concenteric 3 circles, each one can get a color, but not matched with the other circle, how many blobs you can make out of those circles ? this was with the GM ( Augmented Reality SDK) Consider a train, an infinite one, and you looked at the window, and there are two cars, one big, and one small, what is the probability of having only a big car, I said 50%, he said, what if that two cars you dont know their length, and you want to get the probability of getting the biggest one, I struggled, didn't solve it... I was really exahusted after long day of interviews prob of having a number divisible by 5 in numbers from 1 to 100.. struggled!! All coding questions I solved them like reverse a string, detect a cycle in a linked list,..etc.

    Read the article

  • ath9k driver does not weak up

    - by shantanu
    I know this is common question but i found no suitable answer, so i am asking this again. I installed ubuntu 11.10. I found the bug for ath9k, so set first network boot from BIOS menu. That's worked. I have upgraded to 12.04 yesterday. Now ath9k is creating problem again. First network boot is still enable. ath9k works at start. But failed(connect again and again) after couple of minutes. dmesg show error that it can not weak up in 500us. So i tried #compat-wireless-3.5.1-1. But result is same. I have also added #nohwcrypt=1 option in /etc/modeprob.d/ath9k.conf. Still no luck. I tried #rmmod and then modprobe sudo modprobe ath9k nohwcrypt=1 dmesg shows me error: [ 400.690086] ath9k: Driver unloaded [ 406.214329] ath9k 0000:06:00.0: enabling device (0000 -> 0002) [ 406.214348] ath9k 0000:06:00.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17 [ 406.214368] ath9k 0000:06:00.0: setting latency timer to 64 [ 406.428517] ath9k 0000:06:00.0: Failed to initialize device [ 406.428852] ath9k 0000:06:00.0: PCI INT A disabled [ 406.428887] ath9k: probe of 0000:06:00.0 failed with error -5 dmesg error when driver fail: 355.023521] ath: Chip reset failed [ 355.023524] ath: Unable to reset channel, reset status -22 [ 355.023556] ath: Unable to set channel [ 355.088569] ath: Failed to stop TX DMA, queues=0x10f! [ 355.122708] ath: DMA failed to stop in 10 ms AR_CR=0xffffffff AR_DIAG_SW=0xffffffff DMADBG_7=0xffffffff [ 355.122714] ath: Could not stop RX, we could be confusing the DMA engine when we start RX up [ 355.263962] ath: Chip reset failed [ 355.263966] ath: Unable to reset channel (2437 MHz), reset status -22 [ 358.996063] ath: Failed to wakeup in 500us [ 364.004182] ath: Failed to wakeup in 500us I can not install fresh ubuntu because i have lots of application installed. System : Acer Aspire 4250 AMD dual core 1.6GHZ Atheros Communications Inc. AR9485 Wireless Network Adapter (rev 01) EDITED Now i am in serious problem. No wifi device is not showing in ifconfig or lshw commands. Only ether-net interface shows. I tried (FN + WIFI) several times to enable the device but nothing helps. Now I have installed fresh ubuntu 12.04. Please help lshw -c network: *-network description: Ethernet interface product: 82566DC Gigabit Network Connection vendor: Intel Corporation physical id: 19 bus info: pci@0000:00:19.0 logical name: eth0 version: 02 serial: 00:19:d1:7a:8e:f9 size: 100Mbit/s capacity: 1Gbit/s width: 32 bits clock: 33MHz capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=2.0.0-k duplex=full firmware=1.1-0 ip=192.168.1.114 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s resources: irq:45 memory:90300000-9031ffff memory:90324000-90324fff ioport:20c0(size=32) rfkill command does not show anything but no error.

    Read the article

  • Weak reference and Strong reference

    - by theband
    package uk.co.bigroom.utils { import flash.utils.Dictionary; /** * Class to create a weak reference to an object. A weak reference * is a reference that does not prevent the object from being * garbage collected. If the object has been garbage collected * then the get method will return null. */ public class WeakRef { private var dic:Dictionary; /** * The constructor - creates a weak reference. * * @param obj the object to create a weak reference to */ public function WeakRef( obj:* ) { dic = new Dictionary( true ); dic[obj] = 1; } /** * To get a strong reference to the object. * * @return a strong reference to the object or null if the * object has been garbage collected */ public function get():* { for ( var item:* in dic ) { return item; } return null; } } } In this Class, how they denote one as Weak Reference and one as Strong reference.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >